SyncCheck() ) delete_option('acf_flexcol'); if( get_option('acf_flexcol') != 'synced' ) add_filter('acf/settings/load_json', array($this, 'acf_json_load_point') ); if( get_option('acf_flexcol') != 'synced' && $this->SyncCheck() ) { update_option('acf_flexcol', 'synced'); update_option('acf_flexcol_opts', array( 'loadboots' => 1, 'hideposteditor' => 1, 'hidepageeditor' => 1 )); } //Override the_content() to display columns add_filter('the_content', array($this, 'new_the_content') ); //Bootstrap Grid CSS add_action('wp_enqueue_scripts', array($this, 'bootstrap_grids') ); //LI Column CSS add_action('wp_footer', array($this, 'li_columns') ); //LI Column Editor Styles add_action( 'admin_init', array($this, 'add_editor_style') ); //LI Column Editor Scripts add_action( 'after_wp_tiny_mce', array($this, 'add_editor_scripts') ); else: //ALERT and DEACTIVATE - no ACF PRO add_action( 'admin_init', array($this, 'plugin_deactivate') ); add_action( 'admin_notices', array( $this, 'plugin_admin_notice') ); endif; } function plugin_deactivate(){ deactivate_plugins( plugin_basename( __FILE__ ) ); } function plugin_admin_notice(){ $url = 'https://www.advancedcustomfields.com/pro/'; echo '

'.__('ACF Flexible Columns', 'acf-flexible-columns').' '.sprintf( wp_kses( __('requires the Advanced Custom Fields Pro plugin in order to function; the plug-in has been deactivated', 'acf-flexible-columns'), array( 'a' => array( 'href' => array() ) ) ), esc_url( $url ) ).'

'; if ( isset( $_GET['activate'] ) ) unset( $_GET['activate'] ); } function migrate_thecontent(){ global $wpdb; if (isset($_GET['acffc_nonce']) && wp_verify_nonce($_GET['acffc_nonce'], 'migrate_content')): $args = array( 'post_type' => array( 'post', 'page') ); $query = new WP_Query( $args ); if( $query->have_posts() ): while( $query->have_posts() ): $query->the_post(); $oldContent = get_the_content(); $field_key = "field_574881bf81a25"; update_post_meta($query->post->ID, '_rows', $field_key ); update_post_meta($query->post->ID, 'rows', array ('full_width_row') ); update_post_meta($query->post->ID, '_rows_0_column', 'field_574881bf9302c' ); update_post_meta($query->post->ID, 'rows_0_column', array('content') ); update_post_meta($query->post->ID, '_rows_0_column_0_list_layout', 'field_574881bf9dd99' ); update_post_meta($query->post->ID, 'rows_0_column_0_list_layout', 1 ); update_post_meta($query->post->ID, '_rows_0_column_0_content', 'field_574881bf9dd23' ); update_post_meta($query->post->ID, 'rows_0_column_0_content', $oldContent ); endwhile; endif; wp_reset_postdata(); endif; } function add_plugin_page(){ add_options_page( //'edit.php?post_type=acf-field-group', 'ACF Flexible Columns', 'Flexible Columns', 'manage_options', 'acf-flexible-columns', array( $this, 'create_admin_page' ) ); } function create_admin_page(){ $this->options = get_option( 'acf_flexcol_opts' ); ?>

ACF Flexible Columns Settings

Migrate to Column System
This will copy over your previous page content into the new column content system

'; } function load_bootstrap(){ printf( '', isset( $this->options['loadboots'] ) ? esc_attr( 'checked="checked"') : '' ); echo '

'.__('Columns rely on Bootstrap 3 grid styles to function, if you already have Bootstrap 3 styles loaded in your template you can safely disable loading these styles.', 'acf-flexible-columns').'

'; } function hide_post_editor(){ printf( '', isset( $this->options['hideposteditor'] ) ? esc_attr( 'checked="checked"') : '' ); echo '

'.__('The regular Post editor is replaced by the column editor, if you need it back for any reason, uncheck this box', 'acf-flexible-columns').'

'; } function hide_page_editor(){ printf( '', isset( $this->options['hidepageeditor'] ) ? esc_attr( 'checked="checked"') : '' ); echo '

'.__('The regular Page editor is replaced by the column editor, if you need it back for any reason, uncheck this box', 'acf-flexible-columns').'

'; } function SyncCheck(){ global $wpdb; $args = array( 'name' => 'group_574881bf6b7db', 'post_type' => 'acf-field-group', 'post_status' => 'publish', 'numberposts' => 1 ); $synced = get_posts($args); if( $synced ) return true; else return false; } function noeditor(){ $opts = get_option('acf_flexcol_opts'); if( $opts['hideposteditor'] ) remove_post_type_support('post', 'editor'); if( $opts['hidepageeditor'] ) remove_post_type_support('page', 'editor'); } function acf_json_load_point( $paths ){ $paths[] = plugin_dir_path(__FILE__).'acf-json/'; return $paths; } function bootstrap_grids(){ //CSS Styles $opts = get_option('acf_flexcol_opts'); if( $opts['loadboots'] ) wp_enqueue_style( 'BootstrapGrids', plugins_url('assets/bootstrap.grids.min.css', __FILE__), 'all' ); //JS Scripts } function li_columns(){ $opts = get_option('acf_flexcol_opts'); if( !$opts['loadboots'] ){ ?> ', plugins_url('/assets/tinymce-licols.js', __FILE__) ); } function add_editor_style(){ add_editor_style(plugins_url('assets/editor-li-style.css', __FILE__) ); } function new_the_content($content){ global $post; if( have_rows('rows') ): while( have_rows('rows') ): the_row(); if( get_row_layout() == 'full_width_row' ): //SINGLE COLUMN if( have_rows('column') ): while( have_rows('column') ): the_row(); if( get_row_layout() == 'content' ) echo '

'; if( get_row_layout() ) $this->flexible_layout(get_row_layout()); if( get_row_layout() == 'content' ) echo '
'; endwhile; endif; elseif( get_row_layout() == '2_column_row' ): //TWO COLUMNS - COL #1 if( have_rows('column_1') ): while( have_rows('column_1') ): the_row(); if( get_row_layout() == 'content' ) echo '
'; if( get_row_layout() ) $this->flexible_layout(get_row_layout()); endwhile; endif; //TWO COLUMNS - COL #2 if( have_rows('column_2') ): while( have_rows('column_2') ): the_row(); if( get_row_layout() ) $this->flexible_layout(get_row_layout()); if( get_row_layout() == 'content' ) echo '
'; endwhile; endif; elseif( get_row_layout() == '3_column_row' ): //THREE COLUMNS - COL #1 if( have_rows('column_1') ): while( have_rows('column_1') ): the_row(); if( get_row_layout() == 'content' ) echo '
'; if( get_row_layout() ) $this->flexible_layout(get_row_layout()); endwhile; endif; //THREE COLUMNS - COL #2 if( have_rows('column_2') ): while( have_rows('column_2') ): the_row(); if( get_row_layout() ) $this->flexible_layout(get_row_layout()); endwhile; endif; //THREE COLUMNS - COL #3 if( have_rows('column_3') ): while( have_rows('column_3') ): the_row(); if( get_row_layout() ) $this->flexible_layout(get_row_layout()); if( get_row_layout() == 'content' ) echo '
'; endwhile; endif; elseif( get_row_layout() == '4_column_row' ): //FOUR COLUMNS - COL #1 if( have_rows('column_1') ): while( have_rows('column_1') ): the_row(); if( get_row_layout() == 'content' ) echo '
'; if( get_row_layout() ) $this->flexible_layout(get_row_layout()); endwhile; endif; //FOUR COLUMNS - COL #2 if( have_rows('column_2') ): while( have_rows('column_2') ): the_row(); if( get_row_layout() ) $this->flexible_layout(get_row_layout()); endwhile; endif; //FOUR COLUMNS - COL #3 if( have_rows('column_3') ): while( have_rows('column_3') ): the_row(); if( get_row_layout() ) $this->flexible_layout(get_row_layout()); endwhile; endif; //FOUR COLUMNS - COL #4 if( have_rows('column_4') ): while( have_rows('column_4') ): the_row(); if( get_row_layout() ) $this->flexible_layout(get_row_layout()); if( get_row_layout() == 'content' ) echo '
'; endwhile; endif; endif; endwhile; //end rows endif; return $content; } function flexible_layout($type){ switch($type): #CONTENT case 'content': $content = get_sub_field('content'); $width = get_sub_field('width'); if( !$width ): $col = 'col-xs-12'; else: $mdw = $width[0]['desktop']; $smw = $width[0]['tablet']; $xsw = $width[0]['mobile']; $xs = ' col-xs-'.$xsw; if( $smw != $xsw ) $sm = ' col-sm-'.$smw; if( (!$sm && $mdw != $xsw) || ($sm && $mdw != $smw) ) $md = ' col-md-'.$mdw; $col = ltrim($md.$sm.$xs); endif; $licols = get_sub_field('list_layout'); $listyle = false; if( $licols != 1){ $listyle = 'li-col-'.$licols; } if( $listyle ) $content = preg_replace('//m', '