/** * Enqueue and Localize JavaScript for the To-Do List frontend checklist */ public static function frontend_checklist_enqueue_scripts() { wp_enqueue_script('jquery'); wp_enqueue_script('cleverness_todo_checklist_complete_js'); wp_localize_script('cleverness_todo_checklist_complete_js', 'ctdl', CTDL_Loader::get_js_vars()); }
/** * Display the to-do checklist * @param $atts shortcode attributes * @return string To-Do List */ public function display_checklist($atts) { $this->atts = $atts; CTDL_Loader::frontend_checklist_enqueue_scripts(); if (is_user_logged_in()) { $this->display(); } else { $this->list .= esc_html__('You must be logged in to view', 'cleverness-to-do-list'); } return $this->list; }
/** * Create database table and add default options * @static */ public static function install_plugin() { // get database version from options table if (get_option('CTDL_db_version')) { $installed_version = get_option('CTDL_db_version'); } elseif (get_option('cleverness_todo_db_version')) { $installed_version = get_option('cleverness_todo_db_version'); } else { $installed_version = 0; } // check if the db version is the same as the db version constant if ($installed_version != CTDL_DB_VERSION) { include_once plugin_dir_path(__FILE__) . '/cleverness-to-do-list-loader.class.php'; if (!post_type_exists('todo')) { CTDL_Loader::setup_custom_post_type(); } if (!taxonomy_exists('todocategories')) { CTDL_Loader::create_taxonomies(); } // if there was no db version option if ($installed_version == 0) { // check to see if there are any to-do custom posts $existing_todos = self::check_for_todos(); // if not, add the first to-do item if ($existing_todos == 0) { global $current_user; get_currentuserinfo(); // add first post $first_post = __('Add your first To-Do List item', 'cleverness-to-do-list'); $the_post = array('post_type' => 'todo', 'post_title' => substr($first_post, 0, 100), 'post_content' => $first_post, 'post_status' => 'publish', 'post_author' => $current_user->ID, 'comment_status' => 'closed', 'ping_status' => 'closed'); $post_id = wp_insert_post($the_post); add_post_meta($post_id, '_status', 0, true); add_post_meta($post_id, '_priority', 1, true); add_post_meta($post_id, '_assign', -1, true); add_post_meta($post_id, '_deadline', '', true); add_post_meta($post_id, '_progress', 0, true); } self::set_options($installed_version); } else { self::set_options($installed_version); // update db version to current versions update_option('CTDL_db_version', CTDL_DB_VERSION); // if the db version is < 3.0 if ($installed_version < 3) { // check to see if there's existing to-do items. if so, convert them to custom posts $existing_todos = self::check_for_todos(); if ($existing_todos == 0) { self::convert_todos(); } } // if db version < 3.2.1, convert deadlines if (version_compare($installed_version, '3.21', '<')) { self::convert_deadlines(); } // if db version < 3.4, split taxonomies if (version_compare($installed_version, '3.4', '<')) { global $wp_version; if (version_compare($wp_version, '4.2', '>=')) { self::split_taxonomies(); } } } } }
/** * Add Javascript and localize variables */ public function dashboard_add_js() { wp_enqueue_script('ctdl_dashboard_widget_js'); wp_localize_script('ctdl_dashboard_widget_js', 'ctdl', CTDL_Loader::get_js_vars()); }
/** * Define constants and load the plugin */ function cleverness_todo_loader() { if (!defined('CTDL_DB_VERSION')) { define('CTDL_DB_VERSION', '3.4'); } // also update in cleverness_todo_activation at the bottom of this file if (!defined('CTDL_PLUGIN_VERSION')) { define('CTDL_PLUGIN_VERSION', '3.4.2'); } if (!defined('CTDL_FILE')) { define('CTDL_FILE', __FILE__); } if (!defined('CTDL_BASENAME')) { define('CTDL_BASENAME', plugin_basename(__FILE__)); } if (!defined('CTDL_PLUGIN_DIR')) { define('CTDL_PLUGIN_DIR', plugin_dir_path(__FILE__)); } if (!defined('CTDL_PLUGIN_URL')) { define('CTDL_PLUGIN_URL', plugins_url('', __FILE__)); } $language_path = plugin_basename(dirname(__FILE__) . '/languages'); load_plugin_textdomain('cleverness-to-do-list', '', $language_path); include_once 'includes/cleverness-to-do-list-loader.class.php'; CTDL_Loader::init(); if (!defined('CTDL_PP')) { if (in_array('post-planner/post-planner.php', apply_filters('active_plugins', get_option('active_plugins'))) && CTDL_Loader::$settings['post_planner'] == 1) { define('CTDL_PP', true); } else { define('CTDL_PP', false); } } $action = ''; if (isset($_GET['action'])) { $action = $_GET['action']; } if (isset($_POST['action'])) { $action = $_POST['action']; } switch ($action) { case 'addtodo': CTDL_Lib::insert_todo(); break; case 'updatetodo': CTDL_Lib::edit_todo(); break; case 'completetodo': $cleverness_todo_complete_nonce = $_REQUEST['_wpnonce']; if (!wp_verify_nonce($cleverness_todo_complete_nonce, 'todocomplete')) { die(__('Security check failed', 'cleverness-to-do-list')); } CTDL_Lib::complete_todo(absint($_GET['id']), 1); break; case 'uncompletetodo': $cleverness_todo_complete_nonce = $_REQUEST['_wpnonce']; if (!wp_verify_nonce($cleverness_todo_complete_nonce, 'todocomplete')) { die(__('Security check failed', 'cleverness-to-do-list')); } CTDL_Lib::complete_todo(absint($_GET['id']), 0); break; case 'purgetodo': CTDL_Lib::delete_all_completed_todos(); break; case 'deletetables': CTDL_Lib::delete_tables(); break; case 'deletealltodos': CTDL_Lib::delete_all_todos(); break; } }