wpmetabox / meta-box

The best plugin for WordPress custom fields and custom meta boxes
https://metabox.io
1.19k stars 424 forks source link

Noticed issue not showing meta boxes front end or in page edit #1183

Open maxpowdersky opened 7 years ago

maxpowdersky commented 7 years ago

Hi,

I have noticed that the meta boxes are now not displaying frontend or in the page edit screen. I have been declaring the meta boxes using admin_init which after doing some research it is now better to use rwmb_meta_boxes(filter) however I have changed this and the issue still remains. What else is strange is that some of the other meta boxes in the theme do actually work baring a couple.

However:

  1. It is working on my local host (which I have switched files on both but issue still remains)
  2. Downgraded plugin to the same on local but it still remains.

Thanks in advance for your help.

Code for registering meta boxes (one of them that has issue):

<?php
if ( ! defined( 'ABSPATH' ) ) exit;

class OO_BS_Meta_Boxes {

  /**
   * Meta key
   */
  private static $prefix = '_bs_';

  /**
   * Init
   */
  public static function init() {

    // Format admin single
//    add_action( 'admin_init', array( __CLASS__, 'register_meta_boxes' ) );
    add_filter( 'rwmb_meta_boxes', array( __CLASS__, 'register_meta_boxes' ) );

  }

  /**
   * Register Meta Boxes
   */
  public static function register_meta_boxes( $meta_boxes ) {

    // Check template file
    $post_id = $_GET['post'] ? $_GET['post'] : $_POST['post_ID'] ;
    $template_file = get_post_meta( $post_id, '_wp_page_template', true );

    // Check Meta Box plugin installed
  //  if ( !class_exists( 'RW_Meta_Box' ) ) return;

    if($template_file == 'templates/template-page-beginning-skiing.php') {

    // Custom Meta Box
    $meta_boxes[] = array(
      'id'       => 'beg-skiing-author-meta-box',
      'title'    => 'Sections',
      'post_types'    => array( 'page' ),
      'context'  => 'normal',
      'priority' => 'high',

      'fields' => array(
              // Group
              array(
                  'id' => self::$prefix . 'section',
                  'type' => 'group',
                  'clone' => true,
                  'sort_clone' => true,
                  // List of sub-fields
                  'fields' => array(
                      array(
                          'name' => 'Image',
                          'id' => self::$prefix . 'image',
                          'type' => 'image_advanced',
                          'max_file_uploads' => 1
                      ),
                      array(
                          'name' => 'Title',
                          'id' => self::$prefix . 'title',
                          'type' => 'text',
                      ),
                      array(
                          'name' => 'Content',
                          'id' => self::$prefix . 'content',
                          'type' => 'wysiwyg',
                          'options' => array(
                            'media_buttons' => false,
                            'textarea_rows' => 10
                          )
                      ),
                      array(
                          'name' => 'Turn Off?',
                          'id' => self::$prefix . 'turn_off',
                          'type' => 'checkbox',
                      ),
                      array(
                        'id' => self::$prefix . 'buttons',
                        'type' => 'group',
                        'clone' => true,
                        'fields' => array(
                          array(
                              'name' => 'Button Text',
                              'id' => self::$prefix . 'button_text',
                              'type' => 'text',
                          ),
                          array(
                              'name' => 'Button URL',
                              'id' => self::$prefix . 'button_url',
                              'type' => 'text',
                          ),
                        ),
                      ),
                      // Other sub-fields here
                  ),
              ),
          ),
    );

//    foreach( $meta_boxes as $meta_box )
//      new RW_Meta_Box( $meta_box );
////      

    }

             return $meta_boxes;

  }

}

OO_BS_Meta_Boxes::init();

?>
funkatron82 commented 6 years ago

It has to do with the if statement you have. Try using get_page_template() to get the right template file name. Also the file name you are looking for might not be in the right place on the non-local site.

maxpowdersky commented 6 years ago

Sorry for late reply, just got round to looking at this again as put in temporary fix (hard code content on page). It is all in the right location just one day it stopped working on the main site which is very odd. Even copying the main site over to the local it still seems to work so makes me think might have something to do with the PHP settings?