/**
  * Test WP_Customize_Partial::check_capabilities().
  *
  * @see WP_Customize_Partial::check_capabilities()
  */
 function test_check_capabilities()
 {
     wp_set_current_user(self::factory()->user->create(array('role' => 'administrator')));
     do_action('customize_register', $this->wp_customize);
     $partial = new WP_Customize_Partial($this->selective_refresh, 'blogname', array('settings' => array('blogname')));
     $this->assertTrue($partial->check_capabilities());
     $partial = new WP_Customize_Partial($this->selective_refresh, 'blogname', array('settings' => array('blogname', 'non_existing')));
     $this->assertFalse($partial->check_capabilities());
     $this->wp_customize->add_setting('top_secret_message', array('capability' => 'top_secret_clearance'));
     $partial = new WP_Customize_Partial($this->selective_refresh, 'blogname', array('settings' => array('blogname', 'top_secret_clearance')));
     $this->assertFalse($partial->check_capabilities());
     $partial = new WP_Customize_Partial($this->selective_refresh, 'no_setting', array('settings' => array()));
     $this->assertTrue($partial->check_capabilities());
     $partial = new WP_Customize_Partial($this->selective_refresh, 'no_setting', array('settings' => array(), 'capability' => 'top_secret_clearance'));
     $this->assertFalse($partial->check_capabilities());
     $partial = new WP_Customize_Partial($this->selective_refresh, 'no_setting', array('settings' => array(), 'capability' => 'edit_theme_options'));
     $this->assertTrue($partial->check_capabilities());
 }
 /**
  * Renders a specific widget using the supplied sidebar arguments.
  *
  * @since 4.5.0
  * @access public
  *
  * @see dynamic_sidebar()
  *
  * @param WP_Customize_Partial $partial Partial.
  * @param array                $context {
  *     Sidebar args supplied as container context.
  *
  *     @type string $sidebar_id              ID for sidebar for widget to render into.
  *     @type int    $sidebar_instance_number Disambiguating instance number.
  * }
  * @return string|false
  */
 public function render_widget_partial($partial, $context)
 {
     $id_data = $partial->id_data();
     $widget_id = array_shift($id_data['keys']);
     if (!is_array($context) || empty($context['sidebar_id']) || !is_registered_sidebar($context['sidebar_id'])) {
         return false;
     }
     $this->rendering_sidebar_id = $context['sidebar_id'];
     if (isset($context['sidebar_instance_number'])) {
         $this->context_sidebar_instance_number = intval($context['sidebar_instance_number']);
     }
     // Filter sidebars_widgets so that only the queried widget is in the sidebar.
     $this->rendering_widget_id = $widget_id;
     $filter_callback = array($this, 'filter_sidebars_widgets_for_rendering_widget');
     add_filter('sidebars_widgets', $filter_callback, 1000);
     // Render the widget.
     ob_start();
     dynamic_sidebar($this->rendering_sidebar_id = $context['sidebar_id']);
     $container = ob_get_clean();
     // Reset variables for next partial render.
     remove_filter('sidebars_widgets', $filter_callback, 1000);
     $this->context_sidebar_instance_number = null;
     $this->rendering_sidebar_id = null;
     $this->rendering_widget_id = null;
     return $container;
 }
 /**
  * Render a specific widget using the supplied sidebar arguments.
  *
  * @since 4.5.0
  * @access public
  *
  * @see dynamic_sidebar()
  *
  * @param WP_Customize_Partial $partial      Partial.
  * @param array                $context {
  *     Sidebar args supplied as container context.
  *
  *     @type string [$sidebar_id]        ID for sidebar for widget to render into.
  *     @type array  [$sidebar_args]      Sidebar args supplied as container context.
  *     @type string [$sidebar_args_hmac] HMAC for sidebar args.
  * }
  * @return string|false
  */
 public function render_widget_partial($partial, $context)
 {
     $id_data = $partial->id_data();
     $widget_id = array_shift($id_data['keys']);
     $sidebar_id = null;
     $sidebar_args = array();
     if (!is_array($context)) {
         return false;
     }
     if (!empty($context['sidebar_args'])) {
         if (empty($context['sidebar_args_hmac'])) {
             return false;
         }
         $context['sidebar_args'] = $this->ksort_recursive($context['sidebar_args']);
         if (!hash_equals($this->hash_sidebar_args($context['sidebar_args']), $context['sidebar_args_hmac'])) {
             return false;
         }
         $sidebar_args = $context['sidebar_args'];
     }
     /*
      * Note that when a widget is first added to a sidebar, it only has a sidebar_id as context.
      * For existing widgets, and subsequent updates to the newly-added widget, the sidebar_args
      * will be available because they will be included in the partial's rendered response here.
      */
     if (!empty($context['sidebar_id'])) {
         $sidebar_id = $context['sidebar_id'];
     } else {
         if (!empty($sidebar_args['id'])) {
             $sidebar_id = $sidebar_args['id'];
         } else {
             return false;
         }
     }
     if (!is_registered_sidebar($sidebar_id)) {
         return false;
     }
     if (isset($context['sidebar_instance_number'])) {
         $this->context_sidebar_instance_number = $context['sidebar_instance_number'];
     }
     // Filter sidebars_widgets so that only the queried widget is in the sidebar.
     $this->sidebar_args_overrides = $sidebar_args;
     $this->rendering_widget_id = $widget_id;
     $this->rendering_sidebar_id = $sidebar_id;
     $filter_callback = array($this, 'filter_sidebars_widgets_for_rendering_widget');
     add_filter('sidebars_widgets', $filter_callback, 1000);
     // Render the widget.
     ob_start();
     dynamic_sidebar($sidebar_id);
     $container = ob_get_clean();
     // Reset variables for next partial render.
     remove_filter('sidebars_widgets', $filter_callback, 1000);
     $this->context_sidebar_instance_number = null;
     $this->sidebar_args_overrides = array();
     $this->rendering_sidebar_id = null;
     $this->rendering_widget_id = null;
     return $container;
 }