/**
  * Used for attempts to write to a frozen instance.
  *
  * Might be replaced by a child class.
  *
  * @param  string $msg  Error message. Always be specific.
  * @param  string $code Re-use the same code to group error messages.
  * @throws Exception
  * @return void|WP_Error
  */
 private function stop($msg, $code = '')
 {
     if ('' === $code) {
         $code = __CLASS__;
     }
     if (class_exists('WP_Error')) {
         return Mlp_WP_Error_Factory::create($code, $msg);
     }
     throw new Exception($msg, $code);
 }
Ejemplo n.º 2
0
 /**
  * function for custom plugins to get activated on all language blogs
  *
  * @param   int    $element_id ID of the selected element
  * @param   string $type       type of the selected element
  * @param   int    $blog_id    ID of the selected blog
  * @param   string $hook
  * @param   mixed  $param
  * @return  WP_Error|NULL
  */
 public static function run_custom_plugin($element_id, $type, $blog_id, $hook, $param)
 {
     if (empty($element_id)) {
         return Mlp_WP_Error_Factory::create('mlp_empty_custom_element', __('Empty Element', 'multilingual-press'));
     }
     if (empty($type)) {
         return Mlp_WP_Error_Factory::create('mlp_empty_custom_type', __('Empty Type', 'multilingual-press'));
     }
     if (empty($hook) || !is_callable($hook)) {
         return Mlp_WP_Error_Factory::create('mlp_empty_custom_hook', __('Invalid Hook', 'multilingual-press'));
     }
     // set the current element in the mlp class
     $languages = mlp_get_available_languages();
     $current_blog = get_current_blog_id();
     if (0 == count($languages)) {
         return NULL;
     }
     foreach ($languages as $language_id => $language_name) {
         if ($current_blog == $language_id) {
             continue;
         }
         switch_to_blog($language_id);
         /**
          * custom hook
          * @param mixed $param
          */
         do_action($hook, $param);
         restore_current_blog();
     }
     return NULL;
 }