Exemplo n.º 1
0
 /**
  * 
  * @return O2O
  */
 public static function GetInstance()
 {
     if (self::$instance === null) {
         $connection_factory = new O2O_Connection_Factory();
         $query = new O2O_Query($connection_factory);
         self::$instance = new O2O($connection_factory, $query);
     }
     return self::$instance;
 }
Exemplo n.º 2
0
 public function db_update()
 {
     $current_db_version = get_option('o2o_db_version');
     if (version_compare($current_db_version, O2O::DB_VERSION, '<')) {
         WP_CLI::line(sprintf('Current DB version: %s', O2O::DB_VERSION));
         WP_CLI::line('Updating...');
         $o2o = O2O::GetInstance();
         $o2o->db_update();
         WP_CLI::success('Update complete.');
     } else {
         WP_CLI::success('Already up to date.');
     }
 }
 public function test_hierarchical_query()
 {
     global $wpdb;
     $post1 = wp_insert_post(array('post_type' => 'flat_post_type', 'post_title' => 'flat post 1', 'post_status' => 'publish'));
     $post2 = wp_insert_post(array('post_type' => 'flat_post_type', 'post_title' => 'flat post 2', 'post_status' => 'publish'));
     $post3 = wp_insert_post(array('post_type' => 'flat_post_type', 'post_title' => 'flat post 3', 'post_status' => 'publish'));
     $post4 = wp_insert_post(array('post_type' => 'flat_post_type', 'post_title' => 'flat post 4', 'post_status' => 'publish'));
     $hier_parent = wp_insert_post(array('post_type' => 'hier_post_type', 'post_title' => 'hier post 1', 'post_status' => 'publish'));
     $hier_child_1 = wp_insert_post(array('post_type' => 'hier_post_type', 'post_title' => 'hier post 2', 'post_status' => 'publish', 'post_parent' => $hier_parent));
     $hier_child_2 = wp_insert_post(array('post_type' => 'hier_post_type', 'post_title' => 'hier post 3', 'post_status' => 'publish', 'post_parent' => $hier_parent));
     $hier_1_grand_child = wp_insert_post(array('post_type' => 'hier_post_type', 'post_title' => 'hier post 4', 'post_status' => 'publish', 'post_parent' => $hier_child_1));
     $connection_factory = O2O::GetInstance()->get_connection_factory();
     $connection = $connection_factory->get_connection('flat_to_hier');
     $connection->set_connected_to($post1, array($hier_child_1));
     $connection->set_connected_to($post2, array($hier_child_2));
     $connection->set_connected_to($post3, array($hier_1_grand_child));
     $connection->set_connected_to($post4, array($hier_1_grand_child));
     $query = new WP_Query(array('o2o_query' => array('connection' => 'flat_to_hier', 'direction' => 'from', 'id' => $hier_parent), 'fields' => 'ids', 'no_found_rows' => true));
     $post_ids = array_map('intval', $query->get_posts());
     sort($post_ids);
     $expected = array($post1, $post2, $post3, $post4);
     sort($expected);
     $this->assertEquals($expected, $post_ids);
 }
<?php

/*
 Plugin Name: Objects to Objects
 Version:     1.2.4
 Plugin URI:  http://voceplatforms.com
 Description: A WordPress plugin/module that provides the ability to map relationships between posts and other post types.
 Author:      Voce Platforms
 Author URI:  http://voceplatforms.com/
*/
if (!class_exists('O2O')) {
    require_once __DIR__ . '/src/o2o.php';
}
if (!class_exists('O2O_Connection_Factory')) {
    require_once __DIR__ . '/src/factory.php';
}
if (!class_exists('O2O_Query')) {
    require_once __DIR__ . '/src/query.php';
}
if (!class_exists('O2O_Rewrites')) {
    require_once __DIR__ . '/src/rewrites.php';
}
if (!class_exists('O2O_Connection_Taxonomy')) {
    require_once __DIR__ . '/src/connection-types/taxonomy/taxonomy.php';
}
add_action('init', array(O2O::GetInstance(), 'init'), 20);