0,
'exclude' => '',
'hide_empty' => false,
'hierarchical' => 1,
'include' => '',
'include_last_update_time' => false,
'number' => 9999,
'order' => 'ASC',
'orderby' => 'name',
'pad_counts' => false,
);
$terms = get_terms( $taxonomy_name, $args );
if ( ! $terms || is_wp_error($terms) ) {
// No items
return;
}
$db_fields = false;
if ( is_taxonomy_hierarchical( $taxonomy_name ) ) {
$db_fields = array( 'parent' => 'parent', 'id' => 'term_id' );
}
$walker = new cj_Walker_Nav_Menu_Checklist( $db_fields, $boxid, 'category', $taxonomy_selected );
$args['walker'] = $walker;
echo walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $terms), 0, (object) $args );
}
function show_pages_with_checkbox($boxid, $pages_selected) {
$post_type_name = 'page';
$args = array(
'order' => 'ASC',
'orderby' => 'title',
'posts_per_page' => 9999,
'post_type' => $post_type_name,
'suppress_filters' => true,
'update_post_term_cache' => false,
'update_post_meta_cache' => false
);
// @todo transient caching of these results with proper invalidation on updating of a post of this type
$get_posts = new WP_Query;
$posts = $get_posts->query( $args );
if ( ! $get_posts->post_count ) {
// No items
return;
}
$db_fields = false;
if ( is_post_type_hierarchical( $post_type_name ) ) {
$db_fields = array( 'parent' => 'post_parent', 'id' => 'ID' );
}
$walker = new cj_Walker_Nav_Menu_Checklist( $db_fields, $boxid, 'page', $pages_selected );
$post_type_object = get_post_type_object($post_type_name);
$args['walker'] = $walker;
$checkbox_items = walk_nav_menu_tree( array_map('wp_setup_nav_menu_item', $posts), 0, (object) $args );
echo $checkbox_items;
}
//executed if the post arrives initiated by pressing the submit button of form
function on_save_changes() {
//user permission check
if ( !current_user_can('manage_options') )
wp_die( __('Cheatin’ uh?') );
//cross check the given referer
check_admin_referer('cjtoolbox');
// TODO: This is not coded now because we use AJAX. Should be coded to make the plugin work even if javascript is disabled.
//process here your on $_POST validation and / or option saving
//print_r($_POST);
//die();
//lets redirect the post request into get request (you may add additional params at the url, if you need to show save results
wp_redirect(add_query_arg( array('updated' => 'true'), $_POST['_wp_http_referer']));
}
function ajax_add_block() {
check_ajax_referer('cjtoolbox-admin', 'security');
$count = (int) $_POST['count'];
if($count == 0) $count = 1;
$args = array();
$args['args'] = $count;
?>
CSS & JavaScript Block #
cjtoolbox_unit('', $args); ?>
add_cjdata($type, $title, $code);
if($response != false) {
die($response);
}
die('Oops, unable to save '.$type.' code template! Please try again!!!');
}
function ajax_save_changes() {
check_ajax_referer('cjtoolbox-admin', 'security');
if($_POST['action'] == 'cjtoolbox_save') {
// Save data and return 1 on success
$cjdata = $_POST['cjtoolbox'];
foreach($cjdata as $key => $value) {
if($value['code'] == '') {
unset($cjdata[$key]);
}
}
$this->cjdata = $cjdata;
$this->saveData();
return 1; die('1');
}
return 0; // Something wrong!
die(); // this is required to return a proper result
}
function ajax_delete_code() {
check_ajax_referer('cjtoolbox-admin', 'security');
$type = $_POST['type'];
$id = (int) $_POST['id'];
if($id <=0 || ($type != 'js' && $type != 'css')) return 'Invalid Request: Unable to process the request!';
$this->delete_cjdata($type, $id);
die('1');
}
function ajax_get_code() {
check_ajax_referer('cjtoolbox-admin', 'security');
$type = $_POST['type'];
$id = (int) $_POST['id'];
if($id <=0 || ($type != 'js' && $type != 'css')) return 'Invalid Request: Unable to process the request!';
$code = $this->get_cjdata($type, $id);
die($code);
}
function ajax_show_form() {
$type = '';
switch($_GET['type']) {
case 'js':
$type = 'js';
break;
case 'css':
default:
$type = 'css';
break;
}
?>
prepare("SELECT id, title FROM {$wpdb->prefix}cjtoolbox_cjdata WHERE type = '{$type}'");
$list = $wpdb->get_results($query);
if(count($list)) {
echo '';
}
}
function add_cjdata($type, $title, $code) {
global $wpdb;
if($type == '' || $title == '' || $code == '') return false;
$query = $wpdb->prepare("INSERT INTO {$wpdb->prefix}cjtoolbox_cjdata (type,title,code) VALUES ('%s', '%s', '%s')", $type, $title, $code);
$wpdb->query($query);
// Get inserted id
$lastid = $wpdb->get_var("SELECT id FROM {$wpdb->prefix}cjtoolbox_cjdata ORDER BY id DESC LIMIT 0,1");
return $lastid;
}
function delete_cjdata($type, $id) {
global $wpdb;
if($type == '' || $id <= 0) return false;
$query = $wpdb->prepare("DELETE FROM {$wpdb->prefix}cjtoolbox_cjdata WHERE type = '%s' AND id = '%d' LIMIT 1", $type, $id);
$wpdb->query($query);
return true;
}
function get_cjdata($type, $id) {
global $wpdb;
if($type == '' || $id <= 0) return false;
$query = $wpdb->prepare("SELECT code FROM {$wpdb->prefix}cjtoolbox_cjdata WHERE type = '%s' AND id = '%d' LIMIT 1", $type, $id);
$code = $wpdb->get_var($query);
return $code;
}
function activate_plugin() {
global $wpdb;
$database_version = CJTOOLBOX_VERSION;
$installed_db = get_option('cjtoolbox_db_version');
if($database_version != $installed_db) {
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
// Create the table structure
$sql = "CREATE TABLE `{$wpdb->prefix}cjtoolbox_cjdata` (
`id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT ,
`type` VARCHAR( 15 ) NOT NULL ,
`title` TINYTEXT NOT NULL ,
`code` MEDIUMTEXT NOT NULL ,
PRIMARY KEY ( `id` , `type` )
)";
dbDelta($sql);
update_option( "cjtoolbox_db_version", $database_version );
// Add sample code
$count = $wpdb->get_var("SELECT count(*) FROM {$wpdb->prefix}cjtoolbox_cjdata WHERE type='css'");
if($count == 0) {
$wpdb->query("INSERT INTO {$wpdb->prefix}cjtoolbox_cjdata (type,title,code) VALUES ('css','Inline CSS Declaration','')");
$wpdb->query("INSERT INTO {$wpdb->prefix}cjtoolbox_cjdata (type,title,code) VALUES ('css','External Stylesheet','')");
}
$count = $wpdb->get_var("SELECT count(*) FROM {$wpdb->prefix}cjtoolbox_cjdata WHERE type='js'");
if($count == 0) {
$wpdb->query("INSERT INTO {$wpdb->prefix}cjtoolbox_cjdata (type,title,code) VALUES ('js','Inline JavaScript Declaration','')");
$wpdb->query("INSERT INTO {$wpdb->prefix}cjtoolbox_cjdata (type,title,code) VALUES ('js','External JavaScript','')");
}
}
}
}// END Class
// Let's start the plugin
global $cssJSToolbox;
$cssJSToolbox = new cssJSToolbox();
// Activation
register_activation_hook(__FILE__, array(&$cssJSToolbox, "activate_plugin"));
}
/** Following code copied from WordPress core */
/**
* Create HTML list of nav menu input items.
*
* @package WordPress
* @since 3.0.0
* @uses Walker_Nav_Menu
*/
class cj_Walker_Nav_Menu_Checklist extends Walker_Nav_Menu {
function __construct( $fields = false, $boxid = 0, $type = 'page', $selected = array() ) {
if ( $fields ) {
$this->db_fields = $fields;
}
$this->boxid = $boxid;
$this->selected = $selected;
$this->type = $type;
}
function start_lvl( &$output, $depth ) {
$indent = str_repeat( "\t", $depth );
$output .= "\n$indent