if (!defined('CCTM_PATH')) { exit('No direct script access allowed'); } if (!current_user_can('administrator')) { exit('Admins only.'); } require_once CCTM_PATH . '/includes/CCTM_PostTypeDef.php'; require_once CCTM_PATH . '/includes/CCTM_OutputFilter.php'; $data = array(); $data['page_title'] = sprintf(__('Sample Themes for %s', CCTM_TXTDOMAIN), "<em>{$post_type}</em>"); $data['help'] = 'http://code.google.com/p/wordpress-custom-content-type-manager/wiki/SampleTemplates'; $data['menu'] = sprintf('<a href="' . get_admin_url(false, 'admin.php') . '?page=cctm&a=list_post_types" class="button">%s</a>', __('Back', CCTM_TXTDOMAIN)) . ' ' . sprintf('<a href="' . get_admin_url(false, 'admin.php') . '?page=cctm&a=list_custom_field_types&pt=%s" class="button">%s</a>', $post_type, __('Create Custom Field for this Post Type', CCTM_TXTDOMAIN)); $data['msg'] = ''; $data['post_type'] = $post_type; // Validate post type if (!CCTM_PostTypeDef::is_existing_post_type($post_type)) { include CCTM_PATH . '/controllers/error.php'; return; } $current_theme_name = wp_get_theme(); $current_theme_path = get_stylesheet_directory(); $hash = array(); $tpl = file_get_contents(CCTM_PATH . '/tpls/samples/single_post.tpl'); $tpl = htmlspecialchars($tpl); $data['single_page_msg'] = sprintf(__('WordPress supports a custom theme file for each registered post-type (content-type). Copy the text below into a file named <strong>%s</strong> and save it into your active theme.', CCTM_TXTDOMAIN), 'single-' . $post_type . '.php'); $data['single_page_msg'] .= sprintf(__('You are currently using the %1$s theme. Save the file into the %2$s directory.', CCTM_TXTDOMAIN), '<strong>' . $current_theme_name . '</strong>', '<strong>' . $current_theme_path . '</strong>'); // built-in content types don't verbosely display what fields they display /* Array ( [product] => Array (
$data['def'] = self::$default_post_type_def; // $def = self::$post_type_form_definition; // Save data if it was properly submitted if (!empty($_POST) && check_admin_referer($data['action_name'], $data['nonce_name'])) { $sanitized_vals = CCTM_PostTypeDef::sanitize_post_type_def($_POST); $error_msg = CCTM_PostTypeDef::post_type_name_has_errors($sanitized_vals, true); if (empty($error_msg)) { // Clean slate. This nukes any instance of 'is_foreign' (and potentially other issues) // that may arise if the post-type name was used by another plugin and the CCTM tracked // custom fields for that plugin, and then later the other plugin was deactivated and // the CCTM wants to use the same post-type name. unset(CCTM::$data['post_type_defs'][$sanitized_vals['post_type']]); CCTM_PostTypeDef::save_post_type_settings($sanitized_vals); $data['msg'] = CCTM::format_msg(sprintf(__('The content type %s has been created', CCTM_TXTDOMAIN), '<em>' . $sanitized_vals['post_type'] . '</em>')); self::set_flash($data['msg']); include CCTM_PATH . '/controllers/list_post_types.php'; return; } else { // clean up... menu labels in particular can get gunked up. :( $data['def'] = $sanitized_vals; $data['def']['labels']['singular_name'] = ''; $data['def']['label'] = ''; $data['msg'] = CCTM::format_error_msg($error_msg); } } $data['icons'] = CCTM_PostTypeDef::get_post_type_icons(); $data['columns'] = CCTM_PostTypeDef::get_columns($post_type); $data['orderby_options'] = CCTM_PostTypeDef::get_orderby_options($post_type); $data['content'] = CCTM::load_view('post_type.php', $data); print CCTM::load_view('templates/default.php', $data); /*EOF*/
$dir = get_stylesheet_directory(); $oldfilename = $dir . '/single-' . $sanitized_vals['original_post_type_name'] . '.php'; $newfilename = $dir . '/single-' . $sanitized_vals['post_type'] . '.php'; if (file_exists($oldfilename)) { // May generate "Permission denied" warning, so we use @ to suppress it. if (!@rename($oldfilename, $dir . '/single-' . $sanitized_vals['post_type'] . '.php')) { $warning = sprintf(__('You have changed the name of your post_type, so you must also rename your template file! Rename %s to %s.', CCTM_TXTDOMAIN), "<code>{$oldfilename}</code>", '<code>' . basename($newfilename) . '</code>'); self::register_warning($warning); } } } CCTM_PostTypeDef::save_post_type_settings($sanitized_vals); $data['msg'] .= '<div class="updated"><p>' . sprintf(__('Settings for %s have been updated.', CCTM_TXTDOMAIN), '<em>' . $sanitized_vals['post_type'] . '</em>') . '</p></div>'; self::set_flash($data['msg']); print '<script type="text/javascript">window.location.replace("' . get_admin_url(false, 'admin.php') . '?page=cctm");</script>'; return; } else { //print $error_msg; exit; // clean up... menu labels in particular can get gunked up. :( $d['def'] = $sanitized_vals; $d['labels']['singular_name'] = ''; $d['label'] = ''; $data['msg'] = "<div class='error'><p>{$error_msg}</p></div>"; } } $d['icons'] = CCTM_PostTypeDef::get_post_type_icons(); $d['orderby_options'] = CCTM_PostTypeDef::get_orderby_options($post_type); $d['columns'] = CCTM_PostTypeDef::get_columns($post_type); $data['content'] = CCTM::load_view('post_type.php', $d); print CCTM::load_view('templates/default.php', $data); /*EOF*/
// Any validation errors // Save data if it was properly submitted if (!empty($_POST) && check_admin_referer($d['action_name'], $d['nonce_name'])) { $sanitized_vals = CCTM_PostTypeDef::sanitize_post_type_def($_POST); if (isset($d['def']['custom_fields'])) { $sanitized_vals['custom_fields'] = $d['def']['custom_fields']; } else { $sanitized_vals['custom_fields'] = array(); } $error_msg = CCTM_PostTypeDef::post_type_name_has_errors($sanitized_vals, true); if (empty($error_msg)) { CCTM_PostTypeDef::save_post_type_settings($sanitized_vals); $data['msg'] = ' <div class="updated"> <p>' . sprintf(__('The content type %s has been created', CCTM_TXTDOMAIN), '<em>' . $sanitized_vals['post_type'] . '</em>') . '</p> </div>'; self::set_flash($data['msg']); include CCTM_PATH . '/controllers/list_post_types.php'; return; } else { // clean up... menu labels in particular can get gunked up. :( $data['def'] = $sanitized_vals; $data['def']['labels']['singular_name'] = ''; $data['def']['label'] = ''; $data['msg'] = "<div class='error'>{$error_msg}</div>"; } } $d['icons'] = CCTM_PostTypeDef::get_post_type_icons(); $data['content'] = CCTM::load_view('post_type.php', $d); print CCTM::load_view('templates/default.php', $data); /*EOF*/