Retrieves the groups of a module
public static GetCustomGroups ( $customWritePanelId, $orderby = "name" ) : array | ||
Résultat | array | of objects representing basic information of the group, each object contains id, name and module_id |
/** * View groups/fields of a write panel * */ function View() { global $mf_domain; $customWritePanelId = (int) $_REQUEST['custom-write-panel-id']; $customWritePanels = RCCWP_CustomWritePanel::GetCustomWritePanels(); $customWritePanel = RCCWP_CustomWritePanel::Get($customWritePanelId); $custom_groups = RCCWP_CustomWritePanel::GetCustomGroups($customWritePanelId); // get default group id foreach ($custom_groups as $group) { if ($group->name == '__default') { $customDefaultGroupId = $group->id; break; } } ?> <script type="text/javascript" language="javascript"> function confirmBeforeDelete() { return confirm("<?php _e('Are you sure you want to delete this custom Field?', $mf_domain); ?> "); } </script> <div class="wrap"> <form action="<?php echo RCCWP_ManagementPage::GetPanelPage() . "&mf_action=view-custom-write-panel"; ?> " method="post" id="posts-filter" name="SelectWritePanel"> <h2> <?php echo $customWritePanel->name; ?> <span style="font-size:small"> <a href="<?php echo RCCWP_ManagementPage::GetCustomWritePanelGenericUrl('edit-custom-write-panel', $panel->id); ?> " ><?php _e('Edit', $mf_domain); ?> </a>| <a href="<?php echo RCCWP_ManagementPage::GetCustomWritePanelGenericUrl('delete-custom-write-panel', $panel->id); ?> " onclick="return confirmBeforeDelete();"><?php _e('Delete', $mf_domain); ?> </a>| <a href="<?php echo RCCWP_ManagementPage::GetCustomWritePanelGenericUrl('export-custom-write-panel', $panel->id); ?> " ><?php _e('Export', $mf_domain); ?> </a> </span> </h2> <p id="post-search" style="margin-top:6px"> <strong> <?php _e('Choose a Write Panel', $mf_domain); ?> <select name="custom-write-panel-id" style="margin-top:-2px" onchange="document.SelectWritePanel.submit()"> <?php foreach ($customWritePanels as $panel) { ?> <option <?php echo $customWritePanelId == $panel->id ? ' selected ' : ''; ?> value="<?php echo $panel->id; ?> "><?php echo $panel->name; ?> </option> <?php } ?> </select> </strong> <a href="<?php echo RCCWP_ManagementPage::GetCustomWritePanelGenericUrl('create-custom-group'); ?> " class="button-secondary">+ <?php _e('Create a Group', $mf_domain); ?> </a> <a href="<?php echo RCCWP_ManagementPage::GetCustomWritePanelGenericUrl('create-custom-field') . "&custom-group-id={$customDefaultGroupId}"; ?> " class="button-secondary">+ <?php _e('Create a Field', $mf_domain); ?> </a> </p> </form> <br class="clear"/> <table cellpadding="3" cellspacing="3" width="100%" class="widefat"> <thead> <tr> <th width="60%" scope="col"><?php _e('Name', $mf_domain); ?> </th> <th width="20%" scope="col"><?php _e('Type', $mf_domain); ?> </th> <th width="20%" scope="col"><?php _e('Actions', $mf_domain); ?> </th> </tr> </thead> <tbody> <?php foreach ($custom_groups as $group) { if ($customDefaultGroupId != $group->id) { ?> <tr> <td><strong><a style="color:#D54E21" href="<?php echo RCCWP_ManagementPage::GetCustomWritePanelGenericUrl('edit-custom-group') . "&custom-group-id={$group->id}"; ?> "><?php echo $group->name; ?> </a></strong> (<a style="font-size:very-small" href="<?php echo RCCWP_ManagementPage::GetCustomWritePanelGenericUrl('create-custom-field') . "&custom-group-id={$group->id}"; ?> "><?php _e('create field', $mf_domain); ?> </a>) </td> <td><?php _e('Group', $mf_domain); ?> </td> <td><a onclick="return confirmBeforeDelete();" href="<?php echo RCCWP_ManagementPage::GetCustomWritePanelGenericUrl('delete-custom-group') . "&custom-group-id={$group->id}"; ?> ">X <?php _e('Delete', $mf_domain); ?> </a></td> </tr> <?php RCCWP_CustomWritePanelPage::DisplayGroupFields($group->id, true); } } RCCWP_CustomWritePanelPage::DisplayGroupFields($customDefaultGroupId); ?> </tbody> </table> </div> <br /> <?php }
/** * Export a write panel to file * * @param integer $panelID * @param string $exportedFilename the full path of the file to which the panel will be exported */ function Export($panelID) { include_once 'RCCWP_CustomGroup.php'; include_once 'RCCWP_CustomField.php'; $exported_data = array(); $writePanel = RCCWP_CustomWritePanel::Get($panelID); $writePanel->standardFieldsIDs = RCCWP_CustomWritePanel::GetStandardFields($panelID); $writePanel->assignedCategories = array(); $writePanel->theme = RCCWP_CustomWritePanel::GetThemePage($writePanel->name); $writePanel->parent_page = RCCWP_CustomWritePanel::GetParentPage($writePanel->name); $assignedCategories = RCCWP_CustomWritePanel::GetAssignedCategories($panelID); foreach ($assignedCategories as $assignedCategory) { $writePanel->assignedCategories[] = $assignedCategory->cat_id; } $moduleGroups = RCCWP_CustomWritePanel::GetCustomGroups($panelID); foreach ($moduleGroups as $moduleGroup) { $fields = RCCWP_CustomGroup::GetCustomFields($moduleGroup->id); foreach ($fields as $field) { if ($field->type == "Related Type") { $tmp = RCCWP_CustomWritePanel::Get($field->properties["panel_id"]); $field->properties["panel_name"] = $tmp->name; unset($field->properties["panel_id"]); } } $groupFields[$moduleGroup->name]->fields = $fields; $groupFields[$moduleGroup->name]->duplicate = $moduleGroup->duplicate; $groupFields[$moduleGroup->name]->at_right = $moduleGroup->at_right; } $exported_data['panel'] = $writePanel; $exported_data['fields'] = $groupFields; return serialize($exported_data); }
/** * Export a write panel to file * * @param integer $panelID * @param string $exportedFilename the full path of the file to which the panel will be exported */ function Export($panelID, $exportedFilename) { include_once 'RCCWP_CustomGroup.php'; include_once 'RCCWP_CustomField.php'; $exported_data = array(); $writePanel = RCCWP_CustomWritePanel::Get($panelID); $writePanel->standardFieldsIDs = RCCWP_CustomWritePanel::GetStandardFields($panelID); $writePanel->assignedCategories = array(); $writePanel->theme = RCCWP_CustomWritePanel::GetThemePage($writePanel->name); $writePanel->parent_page = RCCWP_CustomWritePanel::GetParentPage($writePanel->name); $assignedCategories = RCCWP_CustomWritePanel::GetAssignedCategories($panelID); foreach ($assignedCategories as $assignedCategory) { $writePanel->assignedCategories[] = $assignedCategory->cat_name; } $moduleGroups = RCCWP_CustomWritePanel::GetCustomGroups($panelID); foreach ($moduleGroups as $moduleGroup) { $groupFields[$moduleGroup->name]->fields = RCCWP_CustomGroup::GetCustomFields($moduleGroup->id); $groupFields[$moduleGroup->name]->duplicate = $moduleGroup->duplicate; $groupFields[$moduleGroup->name]->at_right = $moduleGroup->at_right; } $exported_data['panel'] = $writePanel; $exported_data['fields'] = $groupFields; $handle = fopen($exportedFilename, "w"); $result = fwrite($handle, serialize($exported_data)); @fclose($handle); }
/** * Drawing our custom fields */ function CustomFieldCollectionInterface() { global $CUSTOM_WRITE_PANEL, $wpdb, $mf_domain, $post; if (empty($CUSTOM_WRITE_PANEL)) { return false; } //getting information of the CustomWrite Panel $groups = RCCWP_CustomWritePanel::GetCustomGroups($CUSTOM_WRITE_PANEL->id); foreach ($groups as $group) { //Only is drawed the group if has at least one field $hasfields = RCCWP_CustomGroup::HasCustomfields($group->id); if (!$hasfields) { continue; } if ($group->name == "__default") { $name = "Magic Fields Custom Fields"; } else { $name = $group->name; } add_meta_box('panel_' . $group->id, $name, array('RCCWP_WritePostPage', 'metaboxContent'), $CUSTOM_WRITE_PANEL->type, 'normal', 'high', $group); } }
function CustomFieldCollectionInterface($rightOnly = false) { global $flutter_domain; global $CUSTOM_WRITE_PANEL; global $wpdb; global $post; //if no exists the write panel returni if (!isset($CUSTOM_WRITE_PANEL)) { return; } $customGroups = RCCWP_CustomWritePanel::GetCustomGroups($CUSTOM_WRITE_PANEL->id); foreach ($customGroups as $customGroup) { //render the elements $customFields = RCCWP_CustomGroup::GetCustomFields($customGroup->id); //when will be edit the Post if (isset($_REQUEST['post']) && count($customFields) > 0) { //using the first field name we can know //the order of the groups $firstFieldName = $customFields[0]->name; $order = RCCWP_CustomField::GetOrderDuplicates($_REQUEST['post'], $firstFieldName); ?> <div class="write_panel_wrapper" id="write_panel_wrap_<?php echo $customGroup->id; ?> "><?php //build the group duplicates foreach ($order as $key => $element) { ?> <?php RCCWP_WritePostPage::GroupDuplicate2($customGroup, $element, $key, false); ?> <?php } ?> <?php //knowing what is the biggest duplicate group if (!empty($order)) { $tmp = $order; sort($tmp); $top = $tmp[count($tmp) - 1]; } else { $top = 0; } ?> <input type='hidden' name='g<?php echo $customGroup->id; ?> counter' id='g<?php echo $customGroup->id; ?> counter' value='<?php echo $top; ?> ' /> <input type="hidden" name="rc-custom-write-panel-verify-key" id="rc-custom-write-panel-verify-key" value="<?php echo wp_create_nonce('rc-custom-write-panel'); ?> " /> <input type="hidden" name="rc-cwp-custom-write-panel-id" value="<?php echo $CUSTOM_WRITE_PANEL->id; ?> " /> </div> <?php } else { if (count($customFields) > 0) { ?> <div class="write_panel_wrapper" id="write_panel_wrap_<?php echo $customGroup->id; ?> "> <?php RCCWP_WritePostPage::GroupDuplicate2($customGroup, 1, 1, false); $gc = 1; ?> <input type='hidden' name='g<?php echo $customGroup->id; ?> counter' id='g<?php echo $customGroup->id; ?> counter' value='<?php echo $gc; ?> ' /> <input type='hidden' name="rc-custom-write-panel-verify-key" id="rc-custom-write-panel-verify-key" value="<?php echo wp_create_nonce('rc-custom-write-panel'); ?> " /> <input type='hidden' name="rc-cwp-custom-write-panel-id" value="<?php echo $CUSTOM_WRITE_PANEL->id; ?> " /> </div> <?php } } } }
/** * View groups/fields of a write panel * */ function View() { global $mf_domain; $customWritePanelId = (int) $_REQUEST['custom-write-panel-id']; $customWritePanels = RCCWP_CustomWritePanel::GetCustomWritePanels(); $customWritePanel = RCCWP_CustomWritePanel::Get($customWritePanelId); $custom_groups = RCCWP_CustomWritePanel::GetCustomGroups($customWritePanelId); // get default group id foreach ($custom_groups as $group) { if ($group->name == '__default' && $group->panel_id == $customWritePanelId) { // traversal added extra condition to handle globals $customDefaultGroupId = $group->id; break; } } ?> <script type="text/javascript" language="javascript"> function confirmBeforeDelete() { return confirm("<?php _e('Are you sure you want to delete this custom Field?', $mf_domain); ?> "); } function confirmBeforeDeleteGroup() { return confirm("<?php _e('Are you sure you want to delete this field group?\\n\\nNote: All fields that are part of this group will also be deleted!', $mf_domain); ?> "); } </script> <div class="wrap"> <form action="<?php echo RCCWP_ManagementPage::GetPanelPage() . "&mf_action=view-custom-write-panel"; ?> " method="post" id="posts-filter" name="SelectWritePanel"> <h2> <?php echo $customWritePanel->name; ?> <span style="font-size:small"> <a href="<?php echo RCCWP_ManagementPage::GetCustomWritePanelGenericUrl('edit-custom-write-panel', $customWritePanel->id); ?> " ><?php _e('Edit', $mf_domain); ?> </a>| <a href="<?php echo RCCWP_ManagementPage::GetCustomWritePanelGenericUrl('delete-custom-write-panel', $customWritePanel->id); ?> " onclick="return confirmBeforeDelete();"><?php _e('Delete', $mf_domain); ?> </a>| <a href="<?php echo RCCWP_ManagementPage::GetCustomWritePanelGenericUrl('export-custom-write-panel', $customWritePanel->id); ?> " ><?php _e('Export', $mf_domain); ?> </a> </span> </h2> <p id="post-search" style="margin-top:6px"> <strong> <?php _e('Choose a Write Panel', $mf_domain); ?> <select name="custom-write-panel-id" style="margin-top:-2px" onchange="document.SelectWritePanel.submit()"> <?php foreach ($customWritePanels as $panel) { ?> <option <?php echo $customWritePanelId == $panel->id ? ' selected ' : ''; ?> value="<?php echo $panel->id; ?> "><?php echo $panel->name; ?> </option> <?php } ?> </select> </strong> <a href="<?php echo RCCWP_ManagementPage::GetCustomWritePanelGenericUrl('create-custom-group'); ?> " class="button-secondary">+ <?php _e('Create a Group', $mf_domain); ?> </a> <a href="<?php echo RCCWP_ManagementPage::GetCustomWritePanelGenericUrl('create-custom-field') . "&custom-group-id={$customDefaultGroupId}"; ?> " class="button-secondary">+ <?php _e('Create a Field', $mf_domain); ?> </a> </p> </form> <br class="clear"/> <?php if (isset($_GET['save_order']) && $_GET['saved_order'] == "true") { ?> <div id="message" class="updated"> Saved Order. </div> <?php } ?> <?php foreach ($custom_groups as $group) { ?> <?php if ($group->name == "__default") { ?> <h2>Magic Fields</h2> <?php } else { ?> <h2 class="mf-no-default-group"><a href="<?php echo RCCWP_ManagementPage::GetCustomWritePanelGenericUrl('edit-custom-group') . "&custom-group-id={$group->id}"; ?> "><?php echo $group->name; ?> </a></strong> <span class="mf_add_group_field">(<a href="<?php echo RCCWP_ManagementPage::GetCustomWritePanelGenericUrl('create-custom-field') . "&custom-group-id={$group->id}"; ?> "><?php _e('create field', $mf_domain); ?> </a>)</span> <span class="mf_delete_group_field">(<a onclick="return confirmBeforeDeleteGroup();" href="<?php echo RCCWP_ManagementPage::GetCustomWritePanelGenericUrl('delete-custom-group') . "&custom-group-id={$group->id}"; ?> "><?php _e('delete', $mf_domain); ?> </a>)</span> </h2> <?php } ?> <form action="<?php echo RCCWP_ManagementPage::GetCustomWritePanelGenericUrl('save-fields-order'); ?> " method="post" id="posts-filter" name="ImportWritePanelForm" enctype="multipart/form-data"> <table cellpadding="3" cellspacing="3" width="100%" class="widefat"> <thead> <tr> <th width="5%"></th> <th width="20%" scope="col"><?php _e('Label', $mf_domain); ?> </th> <th width="35%" scope="col"><?php _e('Name (Order)', $mf_domain); ?> </th> <th width="20%" scope="col"><?php _e('Type', $mf_domain); ?> </th> <th width="20%" scope="col"><?php _e('Actions', $mf_domain); ?> </th> </tr> </thead> <tbody class="sortable"> <?php RCCWP_CustomWritePanelPage::DisplayGroupFields($group->id); ?> </tbody> </table> <?php } ?> </div> <br /> <input type="submit" name="save_submit" value="<?php _e('Save Order', $mf_domain); ?> " id="save_order" /> </form> <?php }