예제 #1
0
 /**
  * Constructor.
  *
  * @param string $context Protability context previously registered.
  */
 public function __construct($context)
 {
     if (!current_user_can('switch_themes')) {
         return false;
     }
     if (!($this->instance = et_core_cache_get($context, 'et_core_portability'))) {
         return false;
     }
     if ($this->instance->view) {
         add_action('admin_footer', array($this, 'modal'));
         add_action('customize_controls_print_footer_scripts', array($this, 'modal'));
         add_action('admin_enqueue_scripts', array($this, 'assets'), 5);
     }
 }
예제 #2
0
 /**
  * HTML link to trigger the portability modal.
  *
  * @since 1.0.0
  *
  * @param string $context    The context used to register the portability.
  * @param string $attributes Optional. Query string or array of attributes. Default empty.
  * @return bool Always return true.
  */
 function et_core_portability_link($context, $attributes = array())
 {
     $instance = et_core_cache_get($context, 'et_core_portability');
     if (!current_user_can('switch_themes') || !(isset($instance->view) && $instance->view)) {
         return;
     }
     $defaults = array('title' => esc_attr__('Import & Export', ET_CORE_TEXTDOMAIN));
     $attributes = array_merge($defaults, $attributes);
     // Forced attributes.
     $attributes['href'] = '#';
     $attributes['data-et-core-modal'] = "[data-et-core-portability='{$context}']";
     $string = '';
     foreach ($attributes as $attribute => $value) {
         if (null !== $value) {
             $string .= esc_attr($attribute) . '="' . esc_attr($value) . '" ';
         }
     }
     return sprintf('<a %1$s><span>%2$s</span></a>', trim($string), esc_html($attributes['title']));
 }