/** * Enrich the connection * * @param SP_Connection $connection * * @return SP_Connection $connection */ public function run($connection) { // Check sortable $sortable = 0; if (isset($_POST['sortable']) && $_POST['sortable'] == '1') { $sortable = 1; } $connection->set_sortable($sortable); // Check the display parents $after_post_display_parents = 0; if (isset($_POST['after_post_display_parents']) && $_POST['after_post_display_parents'] == '1') { $after_post_display_parents = 1; } $connection->set_after_post_display_parents($after_post_display_parents); // Check the backwards linking $backwards_linking = 0; if (isset($_POST['backwards_linking']) && $_POST['backwards_linking'] == '1') { $backwards_linking = 1; } $connection->set_backwards_linking($backwards_linking); // Check APDC excerpt $apdc_excerpt = 0; if (isset($_POST['after_post_display_children_excerpt']) && $_POST['after_post_display_children_excerpt'] == '1') { $apdc_excerpt = 1; } $connection->set_after_post_display_children_excerpt($apdc_excerpt); // Check APDC image $apdc_image = 0; if (isset($_POST['after_post_display_children_image']) && $_POST['after_post_display_children_image'] == '1') { $apdc_image = 1; } $connection->set_after_post_display_children_image($apdc_image); return $connection; }
/** * Enrich the connection * * @param SP_Connection $connection * * @return SP_Connection $connection */ public function run($connection) { // Enricht the connection $connection->set_sortable(get_post_meta($connection->get_id(), SP_Constants::PM_PTL_SORTABLE, true)); $connection->set_after_post_display_parents(get_post_meta($connection->get_id(), SP_Constants::PM_PTL_APDP, true)); $connection->set_backwards_linking(get_post_meta($connection->get_id(), SP_Constants::PM_PTL_BACKWARDS, true)); $connection->set_after_post_display_children_excerpt(get_post_meta($connection->get_id(), SP_Constants::PM_PTL_APDC_EXCERPT, true)); $connection->set_after_post_display_children_image(get_post_meta($connection->get_id(), SP_Constants::PM_PTL_APDC_IMAGE, true)); return $connection; }
/** * This function is used to create a connection between two post types. * * The following parameters should be passed when create a post type link: * * Slug (string) – The new slug of the PTL * Title (string) – The new title of the PTL * Parent (string) – The parent post type id * Child (string) – The child post type id * Sortable (int) – Whether the item is sortable. 1 = yes, 0 = no. * Add new (int) – Whether the user can add and link new items. 1 = yes, 0 = no. * Add existing (int) – Whether the user can link existing items. 1 = yes, 0 = no. * After post display children - Display child posts automatically on post. 1 = yes, 0 = no. * After post display parents - Display parent posts automatically on post. 1 = yes, 0 = no. * Backwards Linking - Set to 1 if you want to allow backwards linking. 1 = enabled, 2 = disabled. * Related - Whether this connection is a related conection or not. 1 = enabled, 2 = disabled. * * The function will return a SP_Connection object. * * @since 1.5.0 * @access public * * @param $slug * @param $title * @param $parent * @param $child * @param $sortable * @param $add_new * @param $add_existing * @param $after_post_display_children * @param $after_post_display_parents * @param $backwards_linking * @param $deprecated * * @return SP_Connection */ public function add_connection($slug, $title, $parent, $child, $sortable, $add_new, $add_existing, $after_post_display_children = 0, $after_post_display_parents = 0, $backwards_linking = 0, $deprecated = false) { // Create the Connection Manager $connection_manager = new SP_Connection_Manager(); // Create the connection $connection = new SP_Connection(); $connection->set_slug($slug); $connection->set_title($title); $connection->set_parent($parent); $connection->set_child($child); $connection->set_add_new($add_new); $connection->set_add_existing($add_existing); $connection->set_after_post_display_children($after_post_display_children); $connection->set_sortable($sortable); $connection->set_after_post_display_parents($after_post_display_parents); $connection->set_backwards_linking($backwards_linking); // Save the connection return $connection_manager->save($connection); }