GetCapabilityName() public static method

Create a capability name for a write panel given its name. This function is copied from WP's sanitize_title_with_dashes($title) (formatting.php)
public static GetCapabilityName ( string $customWritePanelName ) : string
$customWritePanelName string panel name
return string capability name
Exemplo n.º 1
0
 /**
  * Updates the properties of a write panel
  *
  * @param integer $customWritePanelId panel id
  * @param string $name write panel name
  * @param string $description write panel description
  * @param array $standardFields a list of standard fields ids that are to be displayed in
  *                                                      in the panel. Use $STANDARD_FIELDS defined in MF_Constant.php
  * @param array $categories array of category ids that are checked by default when the user
  *                                                      opens Write tab for that panel.
  * @param integer $display_order the order of the panel in Magic Fields > Write Panels tab
  * @param string $type 'post' or 'page'
  */
 public static function Update($customWritePanelId, $name, $description = '', $standardFields = array(), $categories = array(), $display_order = 1, $type = FALSE, $createDefaultGroup = true, $single_post = 0, $default_theme_page = NULL, $default_parent_page = NULL, $expanded = 0)
 {
     include_once 'RC_Format.php';
     global $wpdb;
     $capabilityName = RCCWP_CustomWritePanel::GetCapabilityName($name);
     $name = htmlspecialchars($name, ENT_QUOTES, 'UTF-8');
     $description = htmlspecialchars($description, ENT_QUOTES, 'UTF-8');
     $sql = $wpdb->prepare("UPDATE " . MF_TABLE_PANELS . " SET name = %s" . " , description = %s" . " , display_order = %d" . " , capability_name = %s" . " , type = %s" . " , single = %s" . " , expanded = %d" . " where id = %d", array($name, $description, $display_order, $capabilityName, $_POST['radPostPage'], $single_post, $expanded, $customWritePanelId));
     $wpdb->query($sql);
     if (!isset($categories) || empty($categories)) {
         $wpdb->delete(MF_TABLE_PANEL_CATEGORY, array('panel_id' => $customWritePanelId), array('%d'));
     } else {
         $wpdb->delete(MF_TABLE_PANEL_CATEGORY, array('panel_id' => $customWritePanelId), array('%d'));
         foreach ($categories as $cat_id) {
             $wpdb->insert(MF_TABLE_PANEL_CATEGORY, array('panel_id' => $customWritePanelId, 'cat_id' => $cat_id), array('%d', '%s'));
         }
     }
     if (!isset($standardFields) || empty($standardFields)) {
         $wpdb->delete(MF_TABLE_PANEL_STANDARD_FIELD, array('panel_id' => $customWritePanelId), array('%d'));
     } else {
         $currentStandardFieldIds = array();
         $currentStandardFieldIds = RCCWP_CustomWritePanel::GetStandardFields($customWritePanelId);
         Debug::log("currentStandardFieldIds");
         Debug::log($currentStandardFieldIds);
         $keepStandardFieldIds = array_intersect($currentStandardFieldIds, $standardFields);
         $deleteStandardFieldIds = array_diff($currentStandardFieldIds, $keepStandardFieldIds);
         $insertStandardFieldIds = array_diff($standardFields, $keepStandardFieldIds);
         Debug::log("standardFields");
         Debug::log($standardFields);
         Debug::log("keepStandardFieldIds");
         Debug::log($keepStandardFieldIds);
         Debug::log("deleteStandardFieldIds");
         Debug::log($deleteStandardFieldIds);
         Debug::log("insertStandardFieldIds");
         Debug::log($insertStandardFieldIds);
         foreach ($insertStandardFieldIds as $standard_field_id) {
             $wpdb->insert(MF_TABLE_PANEL_STANDARD_FIELD, array('panel_id' => $customWritePanelId, 'standard_field_id' => $standard_field_id), array('%d', '%d'));
         }
         if (!empty($deleteStandardFieldIds)) {
             $ids = implode(',', $deleteStandardFieldIds);
             $sql = $wpdb->prepare("DELETE FROM " . MF_TABLE_PANEL_STANDARD_FIELD . " WHERE panel_id = %d" . " AND standard_field_id IN ({$ids})", array($customWritePanelId));
             $wpdb->query($sql);
         }
     }
     if ($default_theme_page) {
         $theme_key = "t_" . $name;
         //check if exist template in postmeta
         $check_template = $wpdb->prepare("SELECT meta_id FROM {$wpdb->postmeta} WHERE meta_key = %s", array($theme_key));
         $query_template = $wpdb->query($check_template);
         if ($query_template) {
             $sql = $wpdb->prepare("UPDATE {$wpdb->postmeta} SET meta_value = %s WHERE meta_key = %s AND post_id = %s ", array($default_theme_page, $theme_key, "0"));
         } else {
             $sql = $wpdb->prepare("INSERT INTO {$wpdb->postmeta} (meta_key, meta_value) VALUES (%s, %s)", array($theme_key, $default_theme_page));
         }
         $wpdb->query($sql);
     }
     if ($default_parent_page && $default_parent_page >= 0) {
         $parent_key = "p_" . $name;
         //check if exist parent in postmeta
         $check_parent = $wpdb->prepare("SELECT meta_id FROM {$wpdb->postmeta} WHERE meta_key = %s", array($parent_key));
         $query_parent = $wpdb->query($check_parent);
         if ($query_parent) {
             $sql = $wpdb->prepare("UPDATE {$wpdb->postmeta} SET meta_value = %s WHERE meta_key = %s AND post_id = %s", array($default_parent_page, $parent_key, "0"));
         } else {
             $sql = $wpdb->prepare("INSERT INTO {$wpdb->postmeta} (meta_key, meta_value) VALUES (%s, %s)", array($parent_key, $default_parent_page));
         }
         $wpdb->query($sql);
     } elseif ($default_parent_page == -1) {
         delete_post_meta(0, "p_" . $name);
     }
 }
 /**
  * Updates the properties of a write panel
  *
  * @param integer $customWritePanelId panel id
  * @param string $name write panel name
  * @param string $description write panel description
  * @param array $standardFields a list of standard fields ids that are to be displayed in 
  * 							in the panel. Use $STANDARD_FIELDS defined in RCCWP_Constant.php
  * @param array $categories array of category ids that are checked by default when the user
  * 							opens Write tab for that panel.
  * @param integer $display_order the order of the panel in Magic Fields > Write Panels tab
  * @param string $type 'post' or 'page'
  */
 function Update($customWritePanelId, $name, $description = '', $standardFields = array(), $categories = array(), $display_order = 1, $type = FALSE, $createDefaultGroup = true, $single_post = 0, $default_theme_page = NULL, $default_parent_page = NULL)
 {
     include_once 'RC_Format.php';
     global $wpdb;
     $capabilityName = RCCWP_CustomWritePanel::GetCapabilityName($name);
     $sql = sprintf("UPDATE " . MF_TABLE_PANELS . " SET name = %s" . " , description = %s" . " , display_order = %d" . " , capability_name = %s" . " , type = %s" . " , single = %s" . " where id = %d", RC_Format::TextToSql($name), RC_Format::TextToSql($description), $display_order, RC_Format::TextToSql($capabilityName), RC_Format::TextToSql($_POST['radPostPage']), $single_post, $customWritePanelId);
     $wpdb->query($sql);
     if (!isset($categories) || empty($categories)) {
         $sql = sprintf("DELETE FROM " . MF_TABLE_PANEL_CATEGORY . " WHERE panel_id = %d", $customWritePanelId);
         $wpdb->query($sql);
     } else {
         $currentCategoryIds = array();
         $currentCategoryIds = RCCWP_CustomWritePanel::GetAssignedCategoryIds($customWritePanelId);
         $keepCategoryIds = array_intersect($currentCategoryIds, $categories);
         $deleteCategoryIds = array_diff($currentCategoryIds, $keepCategoryIds);
         $insertCategoryIds = array_diff($categories, $keepCategoryIds);
         foreach ($insertCategoryIds as $cat_id) {
             $sql = sprintf("INSERT INTO " . MF_TABLE_PANEL_CATEGORY . " (panel_id, cat_id)" . " values (%d, %d)", $customWritePanelId, $cat_id);
             $wpdb->query($sql);
         }
         if (!empty($deleteCategoryIds)) {
             $sql = sprintf("DELETE FROM " . MF_TABLE_PANEL_CATEGORY . " WHERE panel_id = %d" . " AND cat_id IN (%s)", $customWritePanelId, implode(',', $deleteCategoryIds));
             $wpdb->query($sql);
         }
     }
     if (!isset($standardFields) || empty($standardFields)) {
         $sql = sprintf("DELETE FROM " . MF_TABLE_PANEL_STANDARD_FIELD . " WHERE panel_id = %d", $customWritePanelId);
         $wpdb->query($sql);
     } else {
         $currentStandardFieldIds = array();
         $currentStandardFieldIds = RCCWP_CustomWritePanel::GetStandardFields($customWritePanelId);
         $keepStandardFieldIds = array_intersect($currentStandardFieldIds, $standardFields);
         $deleteStandardFieldIds = array_diff($currentStandardFieldIds, $keepStandardFieldIds);
         $insertStandardFieldIds = array_diff($standardFields, $keepStandardFieldIds);
         foreach ($insertStandardFieldIds as $standard_field_id) {
             $sql = sprintf("INSERT INTO " . MF_TABLE_PANEL_STANDARD_FIELD . " (panel_id, standard_field_id)" . " values (%d, %d)", $customWritePanelId, $standard_field_id);
             $wpdb->query($sql);
         }
         if (!empty($deleteStandardFieldIds)) {
             $sql = sprintf("DELETE FROM " . MF_TABLE_PANEL_STANDARD_FIELD . " WHERE panel_id = %d" . " AND standard_field_id IN (%s)", $customWritePanelId, implode(',', $deleteStandardFieldIds));
             $wpdb->query($sql);
         }
     }
     if ($default_theme_page) {
         $theme_key = "t_" . $name;
         //check if exist template in postmeta
         $check_template = "SELECT meta_id FROM " . $wpdb->postmeta . " WHERE meta_key='" . $theme_key . "' ";
         $query_template = $wpdb->query($check_template);
         if ($query_template) {
             $sql = "UPDATE " . $wpdb->postmeta . " SET meta_value = '" . $default_theme_page . "' " . " WHERE meta_key = '" . $theme_key . "' AND post_id = '0' ";
         } else {
             $sql = "INSERT INTO " . $wpdb->postmeta . " (meta_key, meta_value) " . " VALUES ('" . $theme_key . "', '" . $default_theme_page . "')";
         }
         $wpdb->query($sql);
     }
     if ($default_parent_page && $default_parent_page >= 0) {
         $parent_key = "p_" . $name;
         //check if exist parent in postmeta
         $check_parent = "SELECT meta_id FROM " . $wpdb->postmeta . " WHERE meta_key='" . $parent_key . "' ";
         $query_parent = $wpdb->query($check_parent);
         if ($query_parent) {
             $sql = "UPDATE " . $wpdb->postmeta . " SET meta_value = '" . $default_parent_page . "' " . " WHERE meta_key = '" . $parent_key . "' AND post_id = '0' ";
         } else {
             $sql = "INSERT INTO " . $wpdb->postmeta . " (meta_key, meta_value) " . " VALUES ('" . $parent_key . "', '" . $default_parent_page . "')";
         }
         $wpdb->query($sql);
     } elseif ($default_parent_page == -1) {
         delete_post_meta(0, "p_" . $name, $value);
     }
 }