update_categories(); } } /** * Assign the new categories to the selected opt ins. * * @return void */ private function update_categories() { if (!\wp_verify_nonce($_POST['f12_cf7_doubleoptin_ui_table_options_nonce'], 'f12_cf7_doubleoptin_ui_table_options_action')) { return; } if (!isset($_POST['optin-id']) || !is_array($_POST['optin-id'])) { return; } if (!isset($_POST['category'])) { return; } $category_id = (int)$_POST['category']; $Category = Category::get_by_id($category_id); if (null == $Category && 0 !== $category_id) { return; } $optinIds = array_map('intval', $_POST['optin-id']); foreach ($optinIds as $id) { OptIn::update_category_by_id($id, $category_id); } } /** * Return an Select Field for Categories * * @return string */ public function select_category($selected = 0) { $atts = array( 'perPage' => -1, 'orderBy' => 'name', 'order' => 'ASC' ); $list = Category::get_list($atts, $numberOfPages); $response = ''; foreach ($list as $Category/** @var Category $Category */) { $selected_html = $selected == $Category->get_id() ? 'selected="selected"' : ''; $response .= ''; } return ''; } /** * Add a Option to update the given Categories * * @return string */ public function addOption() { ?>
  • select_category(), array('select' => array('name' => array()), 'option' => array('value' => array(), 'selected' => array()))); ?>