/**
  * Test context calculations for submenus.
  */
 public function test_submenu_contexts()
 {
     $screen = get_current_screen();
     $self = isset($_SERVER['PHP_SELF']) ? $_SERVER['PHP_SELF'] : null;
     $page = isset($_GET['page']) ? $_GET['page'] : null;
     $submenus = _fieldmanager_registry('submenus');
     _fieldmanager_registry('submenus', array());
     // Spoof is_admin().
     set_current_screen('dashboard-user');
     // Submenu of a default WordPress menu.
     $options_submenu = rand_str();
     fm_register_submenu_page($options_submenu, 'options-general.php', 'Options');
     $_SERVER['PHP_SELF'] = '/options-general.php';
     $_GET['page'] = $options_submenu;
     $this->assertEquals(array('submenu', $options_submenu), fm_calculate_context());
     // Submenu of a custom menu.
     $custom_menu_submenu = rand_str();
     fm_register_submenu_page($custom_menu_submenu, rand_str(), 'Custom');
     $_SERVER['PHP_SELF'] = '/admin.php';
     $_GET['page'] = $custom_menu_submenu;
     $this->assertEquals(array('submenu', $custom_menu_submenu), fm_calculate_context());
     // Submenu that Fieldmanager didn't register.
     $_SERVER['PHP_SELF'] = '/themes.php';
     $_GET['page'] = rand_str();
     $this->assertEquals(array(null, null), fm_calculate_context());
     $GLOBALS['current_screen'] = $screen;
     $_SERVER['PHP_SELF'] = $self;
     $_GET['page'] = $page;
     _fieldmanager_registry('submenus', $submenus);
 }
 /**
  * Setup the singleton.
  */
 public function setup()
 {
     /**
      * Filter the capability required to manage the layer priority settings.
      *
      * @param string $capability. Defaults to `manage_options`.
      */
     $this->layer_priority_capability = apply_filters('ad_layers_layer_priority_capability', 'manage_options');
     /**
      * Filter the capability required to manage the custom variables settings.
      *
      * @param string $capability. Defaults to `manage_options`.
      */
     $this->custom_variables_capability = apply_filters('ad_layers_custom_variables_capability', 'manage_options');
     // Register the settings pages
     if (function_exists('fm_register_submenu_page')) {
         if (current_user_can($this->layer_priority_capability)) {
             fm_register_submenu_page('ad_layers', Ad_Layers::instance()->get_edit_link(), __('Layer Priority', 'ad-layers'), null, $this->layer_priority_capability);
         }
         if (current_user_can($this->custom_variables_capability)) {
             fm_register_submenu_page('ad_layers_custom_variables', Ad_Layers::instance()->get_edit_link(), __('Custom Variables', 'ad-layers'), null, $this->custom_variables_capability);
         }
     }
     // Hook the ad layer settings pages onto Fieldmanager's actions
     add_action('fm_submenu_ad_layers', array($this, 'add_layer_priority_settings'));
     add_action('fm_submenu_ad_layers_custom_variables', array($this, 'add_custom_variables_settings'));
     // Load admin-only JS and CSS
     add_action('admin_enqueue_scripts', array($this, 'enqueue_scripts'));
 }
 /**
  * Test context calculations for submenus.
  *
  * @dataProvider submenu_context_args
  */
 public function test_submenu_contexts($parent, $php_self = null)
 {
     $submenu = rand_str();
     fm_register_submenu_page($submenu, $parent, 'Submenu Page');
     $_SERVER['PHP_SELF'] = $php_self ? $php_self : '/' . parse_url($parent, PHP_URL_PATH);
     $query = parse_url($parent, PHP_URL_QUERY);
     if (!empty($query)) {
         parse_str($query, $_GET);
     }
     $_GET['page'] = $submenu;
     $this->assertEquals(array('submenu', $submenu), fm_calculate_context());
 }
 public function setup()
 {
     // When registering a submenu page, the field name is the cable that
     // connects everything. In this case, 'meta_fields' needs to appear as
     // the first arg passed to `fm_register_submenu_page()`, it needs to be
     // in the action (prefixed with `fm_submenu_`), and then it needs to be
     // the field's name.
     fm_register_submenu_page('meta_fields', 'tools.php', 'Meta Fields');
     add_action('fm_submenu_meta_fields', array($this, 'tools_init'));
     fm_register_submenu_page('user_fields', 'users.php', 'Meta Boxes');
     add_action('fm_submenu_user_fields', array($this, 'users_init'));
     fm_register_submenu_page('option_fields', 'options-general.php', 'Meta Boxes');
     add_action('fm_submenu_option_fields', array($this, 'options_init'));
 }
Beispiel #5
0
 /**
  * Constructor.
  * @return void
  */
 public function __construct()
 {
     // Exit if the carousel isn't enabled.
     if (!get_theme_mod('show_carousel', false)) {
         return;
     }
     // Exit if Fieldmanager isn't installed.
     if (!defined('FM_VERSION')) {
         return;
     }
     add_action('page_before_loop', array($this, 'display'));
     add_action('wp_enqueue_scripts', array($this, 'scripts'));
     // Sets admin up.
     fm_register_submenu_page(self::OPTION, 'themes.php', 'Carousel');
     add_action('fm_submenu_' . self::OPTION, array($this, 'settings'));
 }
 /**
  * Setup the singleton.
  *
  * @access public
  */
 public function setup()
 {
     /**
      * Filter the capability required to manage the ad server settings.
      *
      * @param string $capability. Defaults to `manage_options`.
      */
     $this->settings_capability = apply_filters('ad_layers_settings_capability', 'manage_options');
     // Register the settings page
     if (function_exists('fm_register_submenu_page') && current_user_can($this->settings_capability)) {
         fm_register_submenu_page($this->option_name, Ad_Layers::instance()->get_edit_link(), __('Ad Server Settings', 'ad-layers'), null, $this->settings_capability);
     }
     // Hook the ad layer settings page onto Fieldmanager's action.
     add_action('fm_submenu_' . $this->option_name, array($this, 'add_settings_page'));
     // Add the required header and footer setup. May differ for each server.
     add_action('wp_head', array($this, 'header_setup'));
     add_action('wp_footer', array($this, 'footer_setup'));
     // Handle rendering units
     add_action('ad_layers_render_ad_unit', array($this, 'get_ad_unit'));
     // Load the Javascript API early
     add_action('wp_enqueue_scripts', array($this, 'enqueue_scripts'), 5);
     // Load current settings
     self::$settings = apply_filters('ad_layers_ad_server_settings', get_option($this->option_name, array()));
     // Allow additional ad servers to be loaded via filter within a theme
     $this->ad_servers = apply_filters('ad_layers_ad_servers', array('Ad_Layers_DFP' => AD_LAYERS_BASE_DIR . '/php/ad-servers/class-ad-layers-dfp.php'));
     // Load ad server classes
     if (!empty($this->ad_servers) && is_array($this->ad_servers)) {
         foreach ($this->ad_servers as $ad_server) {
             if (file_exists($ad_server)) {
                 require_once $ad_server;
             }
         }
     }
     // Set the current ad server class, if defined.
     if (!empty(self::$settings['ad_server']) && class_exists(self::$settings['ad_server'])) {
         $ad_server = new self::$settings['ad_server']();
         $this->ad_server = $ad_server::instance();
     }
 }
 /**
  * Add in a FM_Byline meta box w/ all it's bells and whistles
  * @param string $type
  * @param string. Optional label
  * @param array $args
  */
 function add_byline_meta_box($type = 'author', $label = null, $args = array())
 {
     if (is_admin()) {
         $context = fm_get_context();
         $fm_context = $context[0];
         $fm_context_type = $context[1];
         $label = empty($label) ? fm_bylines_wordify_slug($type) : $label;
         $defaults = array('name' => 'fm_bylines_' . sanitize_title_with_dashes($type), 'limit' => 0, 'add_more_label' => __('Add another', 'fm_bylines'), 'sortable' => true, 'label' => __('Name', 'fm_bylines'), 'children' => array('byline_id' => new Fieldmanager_Autocomplete(array('default_value' => null, 'datasource' => new Fieldmanager_Datasource_Post(array('query_args' => array('post_type' => $this->name, 'no_found_rows' => true, 'ignore_sticky_posts' => true, 'post_status' => 'publish', 'suppress_filters' => false))))), 'fm_byline_type' => new Fieldmanager_Hidden(array('default_value' => sanitize_title_with_dashes($type)))));
         $fm_byline_box = new Fieldmanager_Group(wp_parse_args($args, $defaults));
         if ('post' == $fm_context) {
             $fm_byline_box->add_meta_box($label, $fm_context_type, apply_filters('fm_bylines_' . sanitize_title_with_dashes($type) . '_filter_post_metabox_context', 'normal'), apply_filters('fm_bylines_' . sanitize_title_with_dashes($type) . '_filter_post_metabox_priority', 'default'));
         } elseif ('term' == $fm_context) {
             $fm_byline_box->add_term_form($label, $fm_context_type);
         } elseif ('submenu' == $fm_context) {
             fm_register_submenu_page('fm_bylines_' . sanitize_title_with_dashes($type), apply_filters('fm_bylines_' . sanitize_title_with_dashes($type) . '_filter_metabox_submenu', 'tools.php'), $label);
             $fm_byline_box->activate_submenu_page();
         } elseif ('user' == $fm_context) {
             $fm_byline_box->add_user_form($label);
         } elseif ('quickedit' == $fm_context) {
             $fm_byline_box->add_quickedit_box($label, $fm_context_type, function ($post_id, $data) {
                 return !empty($data['fm_bylines_' . sanitize_title_with_dashes($type)]) ? $data['fm_bylines_' . sanitize_title_with_dashes($type)] : 'not set';
             });
         }
     }
 }
 public function test_urls()
 {
     $current_user = get_current_user_id();
     wp_set_current_user($this->factory->user->create(array('role' => 'administrator')));
     // Test URL generation with a normal parent, tools.php
     $name_1 = rand_str();
     fm_register_submenu_page($name_1, 'tools.php', 'Testing URLs');
     $context_1 = $this->get_context($name_1);
     // Test with a parent with an additional query arg
     $name_2 = rand_str();
     fm_register_submenu_page($name_2, 'edit.php?post_type=page', 'Testing URLs');
     $context_2 = $this->get_context($name_2);
     // Test with a null parent
     $name_3 = rand_str();
     fm_register_submenu_page($name_3, null, 'Testing URLs');
     $context_3 = $this->get_context($name_3);
     // Test with a parent slug
     $name_4 = rand_str();
     $parent = rand_str();
     add_submenu_page(null, 'Test parent', 'Test parent', 'manage_options', $parent);
     fm_register_submenu_page($name_4, $parent, 'Testing URLs');
     $context_4 = $this->get_context($name_4);
     wp_set_current_user($current_user);
     // We're running the assertions at the end so we can be guaranteed that
     // we set the current user back.
     $this->assertEquals(admin_url('tools.php?page=' . $name_1), $context_1->url());
     $this->assertEquals(admin_url('edit.php?post_type=page&page=' . $name_2), $context_2->url());
     $this->assertEquals(admin_url('admin.php?page=' . $name_3), $context_3->url());
     $this->assertEquals(admin_url('admin.php?page=' . $name_4), $context_4->url());
 }
 public function test_updated_message()
 {
     $name = 'message_customization';
     $updated_message = rand_str();
     fm_register_submenu_page($name, 'tools.php', 'Message Customization');
     $context = $this->get_context($name);
     $context->updated_message = $updated_message;
     $html = $this->get_html($context, $name);
     $this->build_post($html, $name);
     $this->assertContains("<div class=\"updated success\"><p>{$updated_message}</p></div>", $this->get_html($context, $name));
 }
 public function setup()
 {
     fm_register_submenu_page('rss_datasource_settings', 'options-general.php', __('RSS Feed Datasource Settings', 'fm-datasource-rss'), __('RSS Feeds', 'fm-datasource-rss'));
     add_action('fm_submenu_rss_datasource_settings', array($this, 'settings'));
     add_filter('wp_feed_cache_transient_lifetime', array($this, 'cache_duration'), 10, 2);
 }