/** * * Verifies the Grid URL slug is not a WP reserved term * * * @since 3.0 * @param [string] $meta_value value the user entered * @param [array] $args unused * @param [obj] $object contains original value before user input * * @return sanitized value. Either the inputted value if it checks out * or the original value if not * * @access public */ function sanitize_slug($meta_value, $args, $object) { $reserved_terms = mbdb_wp_reserved_terms(); if (in_array($meta_value, $reserved_terms)) { //show a message $msg = '"' . $meta_value . '" ' . __('is a reserved term and not allowed. This field was not saved.', 'mooberry-book-manager'); add_settings_error($this->key . '-error', '', $msg, 'error'); settings_errors($this->key . '-error'); // return the original value return sanitize_title($object->value); } // entered value is OK. Sanitize it and return it return sanitize_title($meta_value); }
<?php require_once './helper-functions.php'; $reserved_terms = mbdb_wp_reserved_terms(); ?> <html> <head> <title><?php _e('Wordpress Reserved Terms', 'mooberry-book-manager'); ?> </title> <style> ul{ width:400px; } li{ float:left; margin:0 10px 10px 0; width:175px; } li:nth-child(even){ margin-right:0; } </style> </head> <body> <h2><?php _e('Wordpress Reserved Terms', 'mooberry-book-manager'); ?> </h2> <ul id="reserved_terms" >
function mbdb_set_default_tax_grid_slugs() { $taxonomies = mbdb_tax_grid_objects(); //get_object_taxonomies( 'mbdb_book', 'objects' ); $mbdb_options = get_option('mbdb_options'); foreach ($taxonomies as $name => $taxonomy) { if ($mbdb_options['mbdb_book_grid_' . $name . '_slug'] == '') { $reserved_terms = mbdb_wp_reserved_terms(); $slug = sanitize_title($taxonomy->labels->singular_name); if (in_array($slug, $reserved_terms)) { $slug = sanitize_title('book-' . $slug); } $mbdb_options['mbdb_book_grid_' . $name . '_slug'] = $slug; } } update_option('mbdb_options', $mbdb_options); }