'; echo '
Plugin Advanced Custom Fields: Theme Code Pro is activated so plugin Advanced Custom Fields: Theme Code has been disabled.
'; echo ''; } /** * Check if ACF plugin is free or pro version */ public function set_db_table() { // If we can't detect ACF if ( ! class_exists( 'acf' ) ) { // bail early return; } // Check for the function acf_get_setting - this came in version 5 if ( function_exists( 'acf_get_setting' ) ) { // Get the version to be sure // This will return a srting of the version eg '5.0.0' $version = acf_get_setting( 'version' ); } else { // Use the version 4 logic to get the version // This will return a string if the plugin is active eg '4.4.11' // This will retrn the string 'version' if the plugin is not active $version = apply_filters( 'acf/get_info', 'version' ); } // Get only the major version from the version string (the first character) $major_version = substr( $version, 0 , 1 ); // If the major version is 5 if( $major_version == '5' ) { // Set the db table to posts self::$db_table = 'posts'; // If the major version is 4 } elseif( $major_version == '4' ) { // Set the db table to postmeta self::$db_table = 'postmeta'; } } /** * Register meta box */ public function register_meta_boxes() { add_meta_box( 'acftc-meta-box', __( 'Theme Code', 'textdomain' ), array( $this, 'display_callback'), array( 'acf', 'acf-field-group' ) // same meta box used for ACF and ACF PRO ); } /** * Meta box display callback * * @param WP_Post $post Current post object. */ public function display_callback( $post ) { if ( self::$db_table == 'postmeta') { // Setup a counter for location rules $location_rules_count = ''; global $wpdb; // Prepend table prefix $table = $wpdb->prefix . 'postmeta'; // Query postmeta table for location rules associated with this field group $query_results = $wpdb->get_results( "SELECT * FROM " . $table . " WHERE post_id = " . $post->ID . " AND meta_key LIKE 'rule'" ); // count the results $location_rules_count = count( $query_results ); // if we have more than 1 location show the notice if( $location_rules_count >= 2 ) { echo ''; } // render the field group $parent_field_group = new ACFTC_Group( $post->ID ); } elseif ( self::$db_table == 'posts') { // count them $field_group_location_array_count = $this->get_field_group_locations( $post ); // if we have more than 1 location show the notice if( $field_group_location_array_count >= 2 ) { echo ''; } // render the field group $parent_field_group = new ACFTC_Group( $post->ID, 0 , 0 , ''); } if ( !empty( $parent_field_group->fields ) ) { $parent_field_group->render_field_group(); // Upgrade to TC Pro notice echo ''; } else { echo 'Create some fields and publish the field group to generate theme code.