/**
  * PHPDOC
  *
  * @param string        $name        PHPDOC
  * @param int           $src_post_id PHPDOC
  * @param boolean|array $ori_post    PHPDOC
  *
  * @return boolean|int PHPDOC
  *
  * @since PHPDOC
  */
 public function create_alternative_copying_content($name, $src_post_id, $ori_post = false)
 {
     require_once NELIOAB_UTILS_DIR . '/wp-helper.php';
     // Retrieve original post
     $src_post = get_post($src_post_id, ARRAY_A);
     if (!$src_post) {
         return false;
     }
     if ($ori_post && $src_post['post_type'] != $ori_post['post_type']) {
         switch ($ori_post['post_type']) {
             case 'page':
                 $aux = NelioABExperiment::PAGE_ALT_EXP;
                 break;
             case 'post':
                 $aux = NelioABExperiment::POST_ALT_EXP;
                 break;
             default:
                 $aux = NelioABExperiment::CPT_ALT_EXP;
         }
         return $this->create_empty_alternative($name, $aux, $ori_post['post_type']);
     }
     // Create new empty post
     $post_data = array('post_author' => $src_post['post_author'], 'post_type' => $src_post['post_type'], 'post_title' => $src_post['post_title'], 'post_content' => $src_post['post_content'], 'post_excerpt' => $src_post['post_excerpt'], 'post_status' => 'draft', 'post_name' => 'nelioab_' . rand(1, 10));
     $new_post_id = wp_insert_post($post_data, true);
     if (is_wp_error($new_post_id)) {
         return false;
     }
     $new_post = get_post($new_post_id, ARRAY_A);
     // Update the post_name
     $new_post['post_name'] = 'nelioab_' . $new_post_id;
     wp_update_post($new_post);
     // Prepare custom metadata
     add_post_meta($new_post_id, '_is_nelioab_alternative', 'true');
     // Override all information
     NelioABWpHelper::overwrite($new_post_id, $src_post_id);
     // Custom Permalinks compatibility
     require_once NELIOAB_UTILS_DIR . '/custom-permalinks-support.php';
     if (NelioABCustomPermalinksSupport::is_plugin_active()) {
         NelioABCustomPermalinksSupport::remove_custom_permalink($new_post_id);
     }
     return $new_post_id;
 }
Ejemplo n.º 2
0
 /**
  * This function hooks all the remaining Nelio components to WordPress.
  *
  * It's a callback of the `init` action, and the reason its hooks are not
  * in the `NelioABController::init` method is because it ends up using a
  * WordPress function that is not available until this point.
  *
  * @return void
  *
  * @see self::init
  * @see self::can_visitor_be_in_experiment
  *
  * @since 2.0.10
  */
 public function do_init()
 {
     // We do not perform AB Testing for certain visitors:
     if (!$this->can_visitor_be_in_experiment()) {
         add_action('wp_enqueue_scripts', array(&$this, 'add_js_for_compatibility'), 10);
         return;
     }
     // Custom Permalinks Support: making sure that we are not redirected while
     // loading an alternative...
     require_once NELIOAB_UTILS_DIR . '/custom-permalinks-support.php';
     if (NelioABCustomPermalinksSupport::is_plugin_active()) {
         NelioABCustomPermalinksSupport::prevent_template_redirect();
     }
     // If we're previewing a page alternative, it may be the case that it's an
     // alternative of the landing page. Let's make sure the "page_on_front"
     // option is properly updated:
     if (isset($_GET['preview']) || isset($_GET['nelioab_show_heatmap'])) {
         add_filter('option_page_on_front', array(&$this, 'fix_page_on_front'));
     }
     // Add support for Google Analytics. Make sure GA tracking scripts are loaded
     // after Nelio's.
     require_once NELIOAB_UTILS_DIR . '/google-analytics-support.php';
     NelioABGoogleAnalyticsSupport::move_google_analytics_after_nelio();
     add_action('wp_enqueue_scripts', array(&$this, 'register_tracking_script'));
     add_action('wp_enqueue_scripts', array(&$this, 'load_tracking_script'), 99);
     add_action('pre_get_posts', array(&$this, 'save_main_query'));
     // LOAD ALL CONTROLLERS
     // Controller for changing a page using its alternatives:
     /** @var $aux NelioABAlternativeExperimentController */
     $aux = $this->controllers['alt-exp'];
     $aux->hook_to_wordpress();
 }