/**
* Create a new write panel.
*
* @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'
* @param boolean $createDefaultGroup indicates whether to create a default group.
* @return the id of the write panel
*/
function Create($name, $description = '', $standardFields = array(), $categories = array(), $display_order = 1, $type = FALSE, $createDefaultGroup = true, $single_post = 0, $default_theme_page)
{
include_once 'RC_Format.php';
global $wpdb;
$capabilityName = RCCWP_CustomWritePanel::GetCapabilityName($name);
if (!$type) {
$type = $_POST['radPostPage'];
}
$sql = sprintf("INSERT INTO " . MF_TABLE_PANELS . " (name, description, display_order, capability_name, type,single)" . " values" . " (%s, %s, %d, %s, %s,%d)", RC_Format::TextToSql($name), RC_Format::TextToSql($description), $display_order, RC_Format::TextToSql($capabilityName), RC_Format::TextToSql($type), $single_post);
$wpdb->query($sql);
$customWritePanelId = $wpdb->insert_id;
if (!isset($categories)) {
$categories = array();
}
foreach ($categories 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 (!isset($standardFields)) {
$standardFields = array();
}
foreach ($standardFields 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);
}
// Create default group
if ($createDefaultGroup) {
include_once 'RCCWP_CustomGroup.php';
RCCWP_CustomGroup::Create($customWritePanelId, '__default', false, false);
}
if ($default_theme_page) {
$theme_key = "t_" . $name;
$sql = "INSERT INTO " . $wpdb->postmeta . " (meta_key, meta_value) " . " VALUES ('" . $theme_key . "', '" . $default_theme_page . "')";
$wpdb->query($sql);
}
RCCWP_CustomWritePanel::AssignToRole($customWritePanelId, 'administrator');
return $customWritePanelId;
}