/** * Checks if name is reserved. * * @param type $name * @return type */ function wpcf_is_reserved_name($name, $check_pages = true) { $name = strval($name); /* * * If name is empty string skip page cause there might be some pages without name */ if ($check_pages && !empty($name)) { global $wpdb; $page = $wpdb->get_var($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_name = %s AND post_type='page'", sanitize_title($name))); if (!empty($page)) { return new WP_Error('wpcf_reserved_name', __('You cannot use this slug because there is already a page by that name. Please choose a different slug.', 'wpcf')); } } $reserved = wpcf_reserved_names(); $name = str_replace('-', '_', sanitize_title($name)); return in_array($name, $reserved) ? new WP_Error('wpcf_reserved_name', __('You cannot use this slug because it is a reserved word, used by WordPress. Please choose a different slug.', 'wpcf')) : false; }
/** * Checks if name is reserved. * * @param type $name * @return type */ function wpcf_is_reserved_name($name, $context, $check_pages = true) { $name = strval($name); /* * * If name is empty string skip page cause there might be some pages without name */ if ($check_pages && !empty($name)) { global $wpdb; $page = $wpdb->get_var($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_name = %s AND post_type='page'", sanitize_title($name))); if (!empty($page)) { return new WP_Error('wpcf_reserved_name', __('You cannot use this slug because there is already a page by that name. Please choose a different slug.', 'wpcf')); } } // Add custom types $custom_types = get_option(WPCF_OPTION_NAME_CUSTOM_TYPES, array()); $post_types = get_post_types(); if (!empty($custom_types)) { $custom_types = array_keys($custom_types); $post_types = array_merge(array_combine($custom_types, $custom_types), $post_types); } // Unset to avoid checking itself if ($context == 'post_type' && isset($post_types[$name])) { unset($post_types[$name]); } // Add taxonomies $custom_taxonomies = (array) get_option(WPCF_OPTION_NAME_CUSTOM_TAXONOMIES, array()); $taxonomies = get_taxonomies(); if (!empty($custom_taxonomies)) { $custom_taxonomies = array_keys($custom_taxonomies); $taxonomies = array_merge(array_combine($custom_taxonomies, $custom_taxonomies), $taxonomies); } // Unset to avoid checking itself if ($context == 'taxonomy' && isset($taxonomies[$name])) { unset($taxonomies[$name]); } $reserved_names = wpcf_reserved_names(); $reserved = array_merge(array_combine($reserved_names, $reserved_names), array_merge($post_types, $taxonomies)); return in_array($name, $reserved) ? new WP_Error('wpcf_reserved_name', __('You cannot use this slug because it is a reserved word, used by WordPress. Please choose a different slug.', 'wpcf')) : false; }
/** * Checks if name is reserved. * * @param type $name * @return type */ function wpcf_is_reserved_name($name, $check_pages = true) { if ($check_pages) { global $wpdb; $page = $wpdb->get_var($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_name = %s AND post_type='page'", sanitize_title($name))); if ($page) { return true; } } $reserved = wpcf_reserved_names(); $name = str_replace('-', '_', sanitize_title($name)); return in_array($name, $reserved); }