Example #1
0
 function cgmp_settings_callback()
 {
     if (!current_user_can('activate_plugins')) {
         wp_die(__('You do not have sufficient permissions to access this page.'));
     }
     if (isset($_POST['cgmp-save-settings'])) {
         update_option(CGMP_DB_SETTINGS_BUILDER_LOCATION, $_POST['builder-under-post']);
         update_option(CGMP_DB_SETTINGS_CUSTOM_POST_TYPES, $_POST['custom-post-types']);
         cgmp_show_message("Settings updated successfully!");
     }
     $template_values = array();
     $template_values = populate_token_builder_under_post($template_values);
     $template_values = populate_token_custom_post_types($template_values);
     echo cgmp_render_template_with_values($template_values, CGMP_HTML_TEMPLATE_PLUGIN_SETTINGS_PAGE);
 }
 function cgmp_saved_shortcodes_callback()
 {
     if (!current_user_can('activate_plugins')) {
         wp_die(__('You do not have sufficient permissions to access this page.'));
     }
     if (isset($_REQUEST['delete_shortcode']) && trim($_REQUEST['delete_shortcode']) != "") {
         $title = $_REQUEST['delete_shortcode'];
         $persisted_shortcodes_json = get_option(CGMP_PERSISTED_SHORTCODES);
         if (isset($persisted_shortcodes_json) && trim($persisted_shortcodes_json) != "") {
             $persisted_shortcodes = json_decode($persisted_shortcodes_json, true);
             if (is_array($persisted_shortcodes)) {
                 if (isset($persisted_shortcodes[$title])) {
                     unset($persisted_shortcodes[$title]);
                     update_option(CGMP_PERSISTED_SHORTCODES, json_encode($persisted_shortcodes));
                     cgmp_show_message("Shortcode deleted successfully!");
                 } else {
                     cgmp_show_message("Could not deleted shortcode!", true);
                 }
             }
         }
     }
     $template_values = array();
     $template_values["CGMP_PLUGIN_IMAGES"] = CGMP_PLUGIN_IMAGES;
     $template_values["SAVED_SHORTCODES_TOKEN"] = "No shortcodes found in the database.";
     $persisted_shortcodes_json = get_option(CGMP_PERSISTED_SHORTCODES);
     if (isset($persisted_shortcodes_json) && trim($persisted_shortcodes_json) != "") {
         $persisted_shortcodes = json_decode($persisted_shortcodes_json, true);
         if (is_array($persisted_shortcodes) && !empty($persisted_shortcodes)) {
             $content = "";
             foreach ($persisted_shortcodes as $shortcode) {
                 $shortcode_id = substr(md5(rand()), 0, 10);
                 if (is_array($shortcode)) {
                     $raw_code = $shortcode['code'];
                     $raw_code = str_replace("TO_BE_GENERATED", $shortcode_id, $raw_code);
                     $content .= "<div style='line-height: 15px; min-height: 20px; height: 20px; width: 70%; padding: 0; margin: 0'>";
                     $content .= "Title: <span style='color: green;'><b>" . $shortcode['title'] . "</b></span>";
                     /* broken with WP 4.0
                     			$content .= "&nbsp;&nbsp;&nbsp;";
                                          $content .= "<a id='".$shortcode['title']."' href='javascript:void(0)' class='insert-shortcode-to-post'>[insert to post]</a>";
                     			*/
                     $content .= "&nbsp;&nbsp;&nbsp;";
                     $content .= "<a href='javascript:void(0)' onclick='return confirmShortcodeDelete(\"admin.php?page=cgmp-saved-shortcodes&delete_shortcode=" . $shortcode['title'] . "\", \"" . $shortcode['title'] . "\");'>";
                     $content .= "<img src='" . CGMP_PLUGIN_IMAGES . "/close.png' border='0' valign='middle' /></a>";
                     $content .= "</div>";
                     $content .= "<div class='loaded-db-shortcodes'><b>" . stripslashes($raw_code) . "</b></div><br />";
                 }
             }
             $template_values["SAVED_SHORTCODES_TOKEN"] = $content;
         }
     }
     echo cgmp_render_template_with_values($template_values, CGMP_HTML_TEMPLATE_PLUGIN_SAVED_SHORTCODES_PAGE);
 }