/** * Checks if Guest Display Name is required or not * * @since 1.1.0 * @return bool */ function sm_is_guest_display_name_required($mockup_id = 0) { if ($mockup_id === 0) { $mockup_id = get_the_ID(); } $mockup = sm_get_mockup($mockup_id); if (is_user_logged_in()) { return false; } if (!$mockup->is_enabled('guest')) { return true; } $post_types = Smart_Mockups_Setup::post_types(); return $post_types[SMART_MOCKUPS_POSTTYPE]['post_meta']['guest_enabled']['default'] ? false : true; }
/** * Register plugin custom post type * * @since 1.0.0 */ public function register_post_types() { $post_types = Smart_Mockups_Setup::post_types(); foreach ($post_types as $post_type => $type_opt) { register_post_type($post_type, array('labels' => array('name' => $type_opt['labels']['name'], 'singular_name' => $type_opt['labels']['singular_name'], 'all_items' => $type_opt['labels']['all_items'], 'new_item' => $type_opt['labels']['new_item'], 'add_new' => $type_opt['labels']['add_new'], 'add_new_item' => $type_opt['labels']['add_new_item'], 'edit_item' => $type_opt['labels']['edit_item'], 'view_item' => $type_opt['labels']['view_item'], 'search_items' => $type_opt['labels']['search_items']), 'rewrite' => $type_opt['rewrite'], 'public' => $type_opt['public'], 'has_archive' => $type_opt['has_archive'], 'menu_icon' => $type_opt['menu_icon'], 'supports' => $type_opt['supports'])); } flush_rewrite_rules(); }
/** * Save plugin custom post meta * * @since 1.0.0 */ public function save_post_meta($post_id) { // Check autosave if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return $post_id; } // Check permissions if (isset($_POST['post_type']) && 'page' == $_POST['post_type']) { if (!current_user_can('edit_page', $post_id)) { return $post_id; } } elseif (!current_user_can('edit_post', $post_id)) { return $post_id; } $post_types = Smart_Mockups_Setup::post_types(); // Check if post type is one of the plugin's if (!in_array(get_post_type(), array_keys($post_types))) { return $post_id; } // Loop through the plugin post types foreach ($post_types as $post_type => $type_opt) { // For each post types, loop through each post meta foreach ($type_opt['post_meta'] as $id => $attr) { $old = get_post_meta($post_id, $id, true); $new = isset($_POST[$id]) ? $_POST[$id] : ''; if ($new && $new != $old) { update_post_meta($post_id, $id, $new); } else { if ('' == $new && $old || !isset($_POST[$id])) { delete_post_meta($post_id, $id, $old); } } } } }
/** * Constructor. * * @since 1.0.5 */ public function __construct($post_id = 0) { $post = get_post($post_id); if (!$post || SMART_MOCKUPS_POSTTYPE !== $post->post_type) { return null; } foreach (get_object_vars($post) as $key => $value) { $this->{$key} = $value; } // Fetch meta data $post_types = Smart_Mockups_Setup::post_types(); foreach ($post_types[$this->post_type]['post_meta'] as $key => $value) { $this->{$key} = $this->get($key); } }
/** * Overrides the custom post type slug * * @since 1.0.0 */ public function override_slug() { $post_types = Smart_Mockups_Setup::post_types(); $default_slug = $post_types[SMART_MOCKUPS_POSTTYPE]['rewrite']['slug']; $slug = get_option('smartmockups_slug', $default_slug); if ($current_rules = get_option('rewrite_rules')) { foreach ($current_rules as $key => $val) { // var_dump( $current_rules );die(); if (strpos($key, $default_slug) !== false) { add_rewrite_rule(str_ireplace($default_slug, $slug, $key), $val, 'top'); } } } flush_rewrite_rules(); }
<form method="post" action="options.php"> <?php $post_types = Smart_Mockups_Setup::post_types(); $settings = array('slug' => sm_get_custom_slug(), 'credits' => get_option('smartmockups_credits', 1)); settings_fields('smartmockups_settings_general'); ?> <table class="form-table"> <tbody> <tr valign="top"> <th scope="row" valign="top"> <label class="description" for="smartmockups_slug"><?php _e('Custom Slug'); ?> </label> </th> <td> <?php echo get_site_url(); ?> / <input id="smartmockups_slug" name="smartmockups_slug" type="text" class="regular-text" value="<?php esc_attr_e($settings['slug']); ?> " /> </td> </tr> <tr valign="top"> <th scope="row" valign="top"> <label class="credits" for="smartmockups_credits"><?php _e('Show Credits');