public function entityManager() { $entityCollection = new EntityCollection(); // SANITIZE ALL DATA if (isset($_POST)) { foreach ($_POST as $key => &$value) { if (is_array($value)) { // FOR ARRAY OBJECT foreach ($value as $keyItem => &$valueItem) { $valueItem = sanitize_text_field($valueItem); } } else { // FOR VALUE $value = sanitize_text_field($value); } } } // check http or https if (isset($_SERVER['HTTPS'])) { $linkToList = 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . '?page=sociallymap-entity-list'; } else { $linkToList = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . '?page=sociallymap-entity-list'; } // ACTION ENTITY : delete if (array_key_exists('sociallymap_deleteEntity', $_POST) && $_POST['sociallymap_deleteEntity']) { $_POST['submit'] = esc_html($_POST['submit']); $idRemoving = $_POST['submit']; $entityCollection->deleteRowsByID($idRemoving); } // ACTION ENTITY : update if (array_key_exists('sociallymap_updateEntity', $_POST) && $_POST['sociallymap_updateEntity']) { if (isset($_POST['sociallymap_name']) && empty($_POST['sociallymap_name'])) { $isValid = false; } if (isset($_POST['sociallymap_entityId']) && empty($_POST['sociallymap_entityId'])) { $isValid = false; } if (!isset($_POST['sociallymap_activate'])) { $_POST['sociallymap_activate'] = 0; } if (!isset($_POST['sociallymap_category'])) { $_POST['sociallymap_category'] = []; } else { foreach ($_POST['sociallymap_category'] as $key => &$value) { $value = esc_html($value); } } if (!isset($_POST['sociallymap_display_type'])) { $_POST['sociallymap_display_type'] = 'tab'; } if (!isset($_POST['sociallymap_link_canonical'])) { $_POST['sociallymap_link_canonical'] = 0; } if (!isset($_POST['sociallymap_noIndex'])) { $_POST['sociallymap_noIndex'] = 0; } if (!isset($_POST['sociallymap_noFollow'])) { $_POST['sociallymap_noFollow'] = 0; } if (!isset($_POST['sociallymap_morebalise'])) { $_POST['sociallymap_morebalise'] = 0; } if (!isset($_POST['sociallymap_readmore'])) { $_POST['sociallymap_readmore'] = ''; } else { $_POST['sociallymap_readmore'] = stripslashes($_POST['sociallymap_readmore']); } $data = ['name' => esc_html($_POST['sociallymap_label']), 'category' => $_POST['sociallymap_category'], 'activate' => esc_html($_POST['sociallymap_activate']), 'sm_entity_id' => esc_html($_POST['sociallymap_entityId']), 'display_type' => esc_html($_POST['sociallymap_display_type']), 'publish_type' => esc_html($_POST['sociallymap_publish_type']), 'link_canonical' => esc_html($_POST['sociallymap_link_canonical']), 'noIndex' => esc_html($_POST['sociallymap_noIndex']), 'noFollow' => esc_html($_POST['sociallymap_noFollow']), 'image' => esc_html($_POST['sociallymap_image']), 'readmore' => esc_html($_POST['sociallymap_readmore']), 'morebalise' => esc_html($_POST['sociallymap_morebalise']), 'id' => esc_html($_GET['id'])]; $entityCollection->update($data); $this->updatePosts(); wp_redirect($linkToList, 301); exit; } // ACTION ENTITY : post if (array_key_exists('sociallymap_postEntity', $_POST) && $_POST['sociallymap_postEntity']) { $isValid = true; if (isset($_POST['sociallymap_name']) && empty($_POST['sociallymap_name'])) { $isValid = false; } if (isset($_POST['sociallymap_entityId']) && empty($_POST['sociallymap_entityId'])) { $isValid = false; } if (!isset($_POST['sociallymap_activate'])) { $_POST['sociallymap_activate'] = 0; } if (!isset($_POST['sociallymap_category'])) { $_POST['sociallymap_category'] = ''; } else { foreach ($_POST['sociallymap_category'] as $key => &$value) { $value = esc_html($value); } } if (!isset($_POST['sociallymap_display_type'])) { $_POST['sociallymap_display_type'] = 'tab'; } if (!isset($_POST['sociallymap_link_canonical'])) { $_POST['sociallymap_link_canonical'] = 0; } if (!isset($_POST['sociallymap_noIndex'])) { $_POST['sociallymap_noIndex'] = 0; } if (!isset($_POST['sociallymap_noFollow'])) { $_POST['sociallymap_noFollow'] = 0; } if (isset($_POST['sociallymap_readmore'])) { $_POST['sociallymap_readmore'] = stripslashes($_POST['sociallymap_readmore']); } else { $_POST['sociallymap_readmore'] = ''; } if (!isset($_POST['sociallymap_morebalise'])) { $_POST['sociallymap_morebalise'] = ''; } if ($isValid == false) { $_POST['sociallymap_isNotValid'] = true; return false; } $data = ['name' => esc_html($_POST['sociallymap_name']), 'category' => $_POST['sociallymap_category'], 'activate' => esc_html($_POST['sociallymap_activate']), 'sm_entity_id' => esc_html($_POST['sociallymap_entityId']), 'publish_type' => esc_html($_POST['sociallymap_publish_type']), 'display_type' => esc_html($_POST['sociallymap_display_type']), 'link_canonical' => esc_html($_POST['sociallymap_link_canonical']), 'noIndex' => esc_html($_POST['sociallymap_noIndex']), 'noFollow' => esc_html($_POST['sociallymap_noFollow']), 'readmore' => esc_html($_POST['sociallymap_readmore']), 'image' => esc_html($_POST['sociallymap_image']), 'morebalise' => esc_html($_POST['sociallymap_morebalise'])]; $entityCollection->add($data); wp_redirect($linkToList, 301); exit; } }