post_id = (int) $post->ID; $this->typenow = $typenow; } // validate post type if( in_array($typenow, array('acf-field-group', 'attachment')) ) { return false; } // validate page (Shopp) if( $pagenow == "admin.php" && isset( $_GET['page'] ) && $_GET['page'] == "shopp-products" && isset( $_GET['id'] ) ) { $return = true; $this->post_id = absint( $_GET['id'] ); $this->typenow = 'shopp_product'; } // return return $return; } /* * admin_enqueue_scripts * * This action is run after post query but before any admin script / head actions. * It is a good place to register all actions. * * @type action (admin_enqueue_scripts) * @date 26/01/13 * @since 3.6.0 * * @param n/a * @return n/a */ function admin_enqueue_scripts() { // validate page if( !$this->validate_page() ) return; // load acf scripts acf_enqueue_scripts(array( 'uploader' => true, )); // actions add_action('acf/input/admin_head', array($this,'admin_head')); add_action('acf/input/admin_footer', array($this,'admin_footer')); } /* * admin_head * * This action will find and add field groups to the current edit page * * @type action (admin_head) * @date 23/06/12 * @since 3.1.8 * * @param n/a * @return n/a */ function admin_head() { // vars $style_found = false; // get field groups $field_groups = acf_get_field_groups(); // add meta boxes if( !empty($field_groups) ) { foreach( $field_groups as $i => $field_group ) { // vars $id = "acf-{$field_group['key']}"; $title = $field_group['title']; $context = $field_group['position']; $priority = 'high'; $args = array( 'field_group' => $field_group, 'visibility' => false ); // tweaks to vars if( $context == 'side' ) { $priority = 'core'; } // filter for 3rd party customization $priority = apply_filters('acf/input/meta_box_priority', $priority, $field_group); // visibility $args['visibility'] = acf_get_field_group_visibility( $field_group, array( 'post_id' => $this->post_id, 'post_type' => $this->typenow )); // add meta box add_meta_box( $id, $title, array($this, 'render_meta_box'), $this->typenow, $context, $priority, $args ); // update style if( !$style_found && $args['visibility'] ) { $style_found = true; $this->style = acf_get_field_group_style( $field_group ); } } } // Allow 'acf_after_title' metabox position add_action('edit_form_after_title', array($this, 'edit_form_after_title')); // remove postcustom metabox (removes expensive SQL query) if( acf_get_setting('remove_wp_meta_box') ) { remove_meta_box( 'postcustom', false, 'normal' ); } // remove ACF values from meta postbox () add_filter('is_protected_meta', array($this, 'is_protected_meta'), 10, 3); } /* * edit_form_after_title * * This action will allow ACF to render metaboxes after the title * * @type action * @date 17/08/13 * * @param n/a * @return n/a */ function edit_form_after_title() { // globals global $post, $wp_meta_boxes; // render post data acf_form_data(array( 'screen' => 'post', 'post_id' => $this->post_id, 'ajax' => 1 )); // render do_meta_boxes( get_current_screen(), 'acf_after_title', $post); // clean up unset( $wp_meta_boxes['post']['acf_after_title'] ); } /* * render_meta_box * * description * * @type function * @date 20/10/13 * @since 5.0.0 * * @param $post_id (int) * @return $post_id (int) */ function render_meta_box( $post, $args ) { // extract args extract( $args ); // all variables from the add_meta_box function extract( $args ); // all variables from the args argument // vars $o = array( 'id' => $id, 'key' => $field_group['key'], 'style' => $field_group['style'], 'label' => $field_group['label_placement'], 'editLink' => '', 'editTitle' => __('Edit field group', 'acf'), 'visibility' => $visibility ); // edit_url if( $field_group['ID'] && acf_current_user_can_admin() ) { $o['editLink'] = admin_url('post.php?post=' . $field_group['ID'] . '&action=edit'); } // load and render fields if( $visibility ) { // load fields $fields = acf_get_fields( $field_group ); // render acf_render_fields( $fields, $this->post_id, 'div', $field_group['instruction_placement'] ); // render replace-me div } else { echo '