'; 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 '
Generate code for each of your Location rules with ACF Theme Code Pro
'; } // 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 '
Generate code for each of your Location rules with ACF Theme Code Pro
'; } // 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 '
Upgrade to ACF Theme Code Pro.
'; } else { echo '

Create some fields and publish the field group to generate theme code.

'; } } /** * Get field group locations * * @param WP_Post $post Current post object. */ private function get_field_group_locations( $post ) { // acf field group global global $field_group; // count the location array $location_array_count = count( $field_group['location'] ); // return the count return $location_array_count; } // load scripts and styles public function enqueue( $hook ) { // grab the post type global $post_type; // if post type is an ACF field group if( 'acf-field-group' == $post_type || 'acf' == $post_type ) { // Plugin styles wp_enqueue_style( 'acftc_css', self::$plugin_url . 'assets/acf-theme-code.css', '' , self::$plugin_version); // Prism (code formatting) wp_enqueue_style( 'acftc_prism_css', self::$plugin_url . 'assets/prism.css', '' , self::$plugin_version); wp_enqueue_script( 'acftc_prism_js', self::$plugin_url . 'assets/prism.js', '' , self::$plugin_version); // Clipboard wp_enqueue_script( 'acftc_clipboard_js', self::$plugin_url . 'assets/clipboard.min.js', '' , self::$plugin_version); // Plugin js wp_enqueue_script( 'acftc_js', self::$plugin_url . 'assets/acf-theme-code.js', array( 'acftc_clipboard_js' ), self::$plugin_version, 'true' ); } } }