/** * Handle post requests * * @access public * @return void */ public function handle_post() { if (isset($_POST['sp_save_check'])) { // Check if user is allowed to do this if (!current_user_can('manage_options')) { return; } // Check nonce if (!isset($_POST['sp_edit_nonce']) || !wp_verify_nonce($_POST['sp_edit_nonce'], plugin_basename(__FILE__))) { return; } $connection = new SP_Connection(); // Check the id $id = isset($_POST['id']) && $_POST['id'] != '' ? $_POST['id'] : null; $connection->set_id($id); // Check the title if (isset($_POST['title']) && $_POST['title'] != '') { $connection->set_title($_POST['title']); } // Check the slug $slug = ''; if (isset($_POST['slug']) && $_POST['slug'] != '') { $slug = $_POST['slug']; } else { $slug = sanitize_title_with_dashes($_POST['title']); } $connection->set_slug($slug); // Parent $connection->set_parent(trim($_POST['parent'])); // Child $connection->set_child(trim($_POST['child'])); // Check the add new $add_new = 0; if (isset($_POST['add_new']) && $_POST['add_new'] == '1') { $add_new = 1; } $connection->set_add_new($add_new); // Check the add existing $add_existing = 0; if (isset($_POST['add_existing']) && $_POST['add_existing'] == '1') { $add_existing = 1; } $connection->set_add_existing($add_existing); // Check the display children $after_post_display_children = 0; if (isset($_POST['after_post_display_children']) && $_POST['after_post_display_children'] == '1') { $after_post_display_children = 1; } $connection->set_after_post_display_children($after_post_display_children); /** * Action: 'pc_connection_catch_post' - Action that is ran after the connection form data is post but before the connection is saved * * @api SP_Connection $connection The Connection */ $connection = apply_filters('pc_connection_catch_post', $connection); // Save the link $pt_link_manager = new SP_Connection_Manager(); $pt_link_manager->save($connection); wp_redirect(get_admin_url() . 'admin.php?page=post_connector'); exit; } }
/** * Method to get a Connection by id * * @access public * * @param int $id * * @return SP_Connection */ public function get_connection($id) { $connection = null; $connection_query = new WP_Query(array('p' => $id, 'post_type' => SP_Constants::CPT_PT_LINK, 'posts_per_page' => '1')); if ($connection_query->have_posts()) { $connection_query->next_post(); // Create the connection $connection = new SP_Connection(); // Set the connection properties $connection->set_id($connection_query->post->ID); $connection->set_slug(get_post_meta($connection_query->post->ID, SP_Constants::PM_PTL_SLUG, true)); $connection->set_title(get_post_meta($connection_query->post->ID, SP_Constants::PM_PTL_TITLE, true)); $connection->set_parent(get_post_meta($connection_query->post->ID, SP_Constants::PM_PTL_PARENT, true)); $connection->set_child(get_post_meta($connection_query->post->ID, SP_Constants::PM_PTL_CHILD, true)); $connection->set_add_new(get_post_meta($connection_query->post->ID, SP_Constants::PM_PTL_ADD_NEW, true)); $connection->set_add_existing(get_post_meta($connection_query->post->ID, SP_Constants::PM_PTL_ADD_EXISTING, true)); $connection->set_after_post_display_children(get_post_meta($connection_query->post->ID, SP_Constants::PM_PTL_APDC, true)); /** * Action: 'pc_connection_init' - Action that is ran after the connection is initialized * * @api SP_Connection $connection The Connection */ $connection = apply_filters('pc_connection_init', $connection); } return $connection; }