コード例 #1
0
 /**
  * Create instances, and register callbacks.
  *
  * @return void
  */
 public function setup()
 {
     $nonce = Mlp_Nonce_Validator_Factory::create('save_redirect_site_setting');
     $data = new Mlp_Redirect_Settings_Data($nonce, $this->option_name);
     $view = new Mlp_Redirect_Site_Settings_Form($nonce, $data);
     add_filter('mlp_blogs_add_fields', array($view, 'render'));
     add_filter('mlp_blogs_save_fields', array($data, 'save'));
 }
コード例 #2
0
 /**
  * Initializes the objects.
  *
  * @return void
  */
 public function setup()
 {
     $meta_key = 'mlp_redirect';
     $nonce = Mlp_Nonce_Validator_Factory::create('save_redirect_user_setting');
     $user_settings_controller = new Mlp_User_Settings_Controller(new Mlp_Redirect_User_Settings_Html($meta_key, $nonce), new Mlp_User_Settings_Updater($meta_key, $nonce));
     $user_settings_controller->setup();
     $redirect_filter = new Mlp_Redirect_Filter($meta_key);
     add_filter('mlp_do_redirect', array($redirect_filter, 'filter_redirect'));
 }
コード例 #3
0
 /**
  * Constructor
  *
  * @param  Inpsyde_Property_List_Interface $data
  */
 public function __construct(Inpsyde_Property_List_Interface $data)
 {
     $this->plugin_data = $data;
     $this->nonce_validator = Mlp_Nonce_Validator_Factory::create('save_cpt_translator_settings');
     // Quit here if module is turned off
     if (!$this->register_setting()) {
         return;
     }
     add_filter('mlp_allowed_post_types', array($this, 'filter_allowed_post_types'));
     add_action('mlp_modules_add_fields', array($this, 'draw_options_page_form_fields'));
     // Use this hook to handle the user input of your modules' options page form fields
     add_action('mlp_modules_save_fields', array($this, 'save_options_page_form_fields'));
     // replace the permalink if selected
     add_action('mlp_before_link', array($this, 'before_mlp_link'));
     add_action('mlp_after_link', array($this, 'after_mlp_link'));
 }
コード例 #4
0
 /**
  * Constructor
  *
  * @param Mlp_Module_Manager_Interface $module_manager
  * @param Mlp_Language_Api_Interface   $language_api
  * @param Mlp_Assets_Interface         $assets
  */
 public function __construct(Mlp_Module_Manager_Interface $module_manager, Mlp_Language_Api_Interface $language_api, Mlp_Assets_Interface $assets)
 {
     $this->module_manager = $module_manager;
     $this->language_api = $language_api;
     $this->assets = $assets;
     // Quit here if module is turned off
     if (!$this->register_setting()) {
         return;
     }
     $this->nonce_validator = Mlp_Nonce_Validator_Factory::create('save_quicklink_position');
     $this->redirect_quick_link();
     add_action('wp_head', array($this, 'load_style'), 0);
     add_filter('the_content', array($this, 'frontend_tab'));
     add_action('mlp_modules_add_fields', array($this, 'draw_options_page_form_fields'));
     // Use this hook to handle the user input of your modules' options page form fields
     add_filter('mlp_modules_save_fields', array($this, 'save_options_page_form_fields'));
 }
コード例 #5
0
 /**
  * Save the post to the blogs
  *
  * @param int     $post_id
  * @param WP_Post $post
  *
  * @return void
  */
 public function save($post_id, WP_Post $post)
 {
     if (!$this->is_valid_save_request($post)) {
         return;
     }
     $available_blogs = get_site_option('inpsyde_multilingual');
     if (empty($available_blogs)) {
         return;
     }
     // auto-drafts
     $post_id = $this->basic_data->get_real_post_id($post_id);
     $post_type = $this->basic_data->get_real_post_type($post);
     $source_blog_id = get_current_blog_id();
     $thumb_data = $this->get_source_thumb_data($post_id);
     $related_blogs = $this->relations->get_related_sites($source_blog_id);
     if (empty($related_blogs)) {
         return;
     }
     // Check Post Type
     if (!in_array($post_type, $this->allowed_post_types)) {
         return;
     }
     $this->save_context = array('source_blog' => get_current_blog_id(), 'source_post' => $post, 'real_post_type' => $post_type, 'real_post_id' => $post_id);
     $this->basic_data->set_save_context($this->save_context);
     $post_meta = $this->basic_data->get_post_meta_to_transfer();
     $this->basic_data->find_post_parents($post_type, $post->post_parent);
     /**
      * Runs before the first save_post action is called for the remote blogs.
      *
      * @param array $save_context Context of the to-be-saved post.
      */
     do_action('mlp_before_post_synchronization', $this->save_context);
     foreach ($this->post_request_data[$this->name_base] as $remote_blog_id => $post_data) {
         if (!blog_exists($remote_blog_id) || !in_array($remote_blog_id, $related_blogs)) {
             continue;
         }
         $nonce_validator = Mlp_Nonce_Validator_Factory::create("save_translation_of_post_{$post->ID}_for_site_{$remote_blog_id}", $source_blog_id);
         $request_validator = Mlp_Save_Post_Request_Validator_Factory::create($nonce_validator);
         if (!$request_validator->is_valid($post)) {
             continue;
         }
         switch_to_blog($remote_blog_id);
         $this->save_context['target_blog_id'] = $remote_blog_id;
         $new_post = $this->create_post_to_send($post_data, $post_type, $remote_blog_id);
         if (array() !== $new_post) {
             $sync_thumb = !empty($post_data['thumbnail']);
             $update = !empty($post_data['remote_post_id']) && 0 < $post_data['remote_post_id'];
             $new_id = $this->sync_post($new_post, $post_id, $remote_blog_id, $update);
             $this->basic_data->set_save_context($this->save_context);
             $this->basic_data->update_remote_post_meta($new_id, $post_meta);
             if ($sync_thumb && $thumb_data->has_thumb) {
                 $this->copy_thumb($new_id, $thumb_data);
             }
             $tax_data = empty($post_data['tax']) ? array() : (array) $post_data['tax'];
             $this->set_remote_tax_terms($new_id, $tax_data);
         }
         restore_current_blog();
     }
     /**
      * Runs after all save_post actions have been called for the remote blogs.
      *
      * @param array $save_context
      */
     do_action('mlp_after_post_synchronization', $this->save_context);
 }
コード例 #6
0
 /**
  * Register one box for each connected site.
  *
  * @param int     $blog_id
  * @param WP_Post $post
  * @param int     $current_blog_id
  *
  * @return void
  */
 private function register_metabox_per_language($blog_id, WP_Post $post, $current_blog_id)
 {
     $remote_post = $this->data->get_remote_post($post, $blog_id);
     $lang = $this->data->get_remote_language($blog_id);
     $title = $this->get_metabox_title($blog_id, $remote_post, $lang);
     $metabox_data = array('remote_blog_id' => $blog_id, 'remote_post' => $remote_post, 'language' => $lang);
     $nonce_validator = Mlp_Nonce_Validator_Factory::create("save_translation_of_post_{$post->ID}_for_site_{$blog_id}", $current_blog_id);
     $view = new Mlp_Translation_Metabox_View($nonce_validator);
     add_meta_box("inpsyde_multilingual_{$blog_id}", $title, array($view, 'render'), null, 'advanced', 'default', $metabox_data);
     if (empty($remote_post->dummy)) {
         $this->register_metabox_view_details($view, $post, $blog_id);
     } else {
         $callback = array($view, 'show_translation_checkbox');
         /**
          * Filter the post translator activation checkbox callback.
          *
          * @param array|string $callback Callback name or class-method array.
          *
          * @return array|string
          */
         $checkbox_callback = apply_filters('mlp_post_translator_activation_checkbox', $callback);
         if ($checkbox_callback) {
             add_action("mlp_translation_meta_box_top_{$blog_id}", $checkbox_callback, 10, 3);
         }
     }
     /**
      * Runs after registration of the meta box for the given blog's language.
      *
      * @param WP_Post $post    Post object.
      * @param int     $blog_id Blog ID.
      */
     do_action('mlp_translation_meta_box_registered', $post, $blog_id);
 }
コード例 #7
0
 /**
  * Create nonce, view and data objects.
  *
  * @wp-hook inpsyde_mlp_loaded
  *
  * @return void
  */
 private function create_instances()
 {
     $nonce_validator = Mlp_Nonce_Validator_Factory::create('add_languages_to_nav_menu');
     $this->data = new Mlp_Language_Nav_Menu_Data($this->handle, $this->meta_key, $nonce_validator, $this->assets);
     $this->view = new Mlp_Simple_Nav_Menu_Selectors($this->data);
 }
コード例 #8
0
 /**
  * @param Mlp_Content_Relations_Interface $content_relations
  */
 public function __construct(Mlp_Content_Relations_Interface $content_relations)
 {
     $this->content_relations = $content_relations;
     $this->nonce = Mlp_Nonce_Validator_Factory::create($this->get_nonce_action(), get_current_blog_id());
 }