public function create_layout_for_this_cpt() { global $post; if (user_can_create_layouts()) { ?> <a href="#" class="add-new-h2 js-create-layout-for-post-custom create-layout-for-page"><?php printf(__('Create a new layout for this %s', 'ddl-layouts'), rtrim($post->post_type, 's')); ?> </a> <?php } else { ?> <button disabled class="add-new-disabled"><?php printf(__('Create a new layout for this %s', 'ddl-layouts'), rtrim($post->post_type, 's')); ?> </button><br> <?php } }
public function duplicate_layout_callback() { // Clear any errors that may have been rendered that we don't have control of. if (ob_get_length()) { ob_clean(); } if (user_can_create_layouts() === false) { die(WPDD_Utils::ajax_caps_fail(__METHOD__)); } if ($_POST && wp_verify_nonce($_POST['layout-duplicate-layout-nonce'], 'layout-duplicate-layout-nonce')) { global $wpdb, $wpddlayout; $result = $wpdb->get_row($wpdb->prepare("SELECT ID, post_name FROM {$wpdb->posts} WHERE post_type=%s AND ID=%d AND post_status = 'publish'", WPDDL_LAYOUTS_POST_TYPE, $_POST['layout_id'])); if ($result) { $layout_json = WPDD_Layouts::get_layout_settings($result->ID); $layout_array = json_decode($layout_json, true); $layout_name_base = __('Copy of ', 'ddl-layouts') . str_replace('\\', '\\\\', $layout_array['name']); $layout_name = $layout_name_base; $count = 1; while ($wpddlayout->does_layout_with_this_name_exist($layout_name)) { $layout_name = $layout_name_base . ' - ' . $count; $count++; } $postarr = array('post_title' => $layout_name, 'post_content' => '', 'post_status' => 'publish', 'post_type' => WPDDL_LAYOUTS_POST_TYPE); $post_id = wp_insert_post($postarr); $post_slug = $wpdb->get_var($wpdb->prepare("SELECT post_name FROM {$wpdb->posts} WHERE post_type=%s AND ID=%d", WPDDL_LAYOUTS_POST_TYPE, $post_id)); $layout_array['name'] = $layout_name; $layout_array['slug'] = $post_slug; WPDD_Layouts::save_layout_settings($post_id, $layout_array); $wpddlayout->register_strings_for_translation($post_id); } $send = $wpddlayout->listing_page->get_send(isset($_GET['status']) && $_GET['status'] === 'trash' ? $_GET['status'] : 'publish', false, $post_id, $post_id, '', $_POST); } else { $send = wp_json_encode(array('error' => __(sprintf('Nonce problem: apparently we do not know where the request comes from. %s', __METHOD__), 'ddl-layouts'))); } die($send); }
public function listing_scripts() { global $wpddlayout; //speed up ajax calls sensibly wp_deregister_script('heartbeat'); wp_register_script('heartbeat', false); $localization_array = array('res_path' => WPDDL_RES_RELPATH, 'listing_lib_path' => WPDDL_GUI_RELPATH . "/listing/js/", 'editor_lib_path' => WPDDL_GUI_RELPATH . "editor/js/", 'common_rel_path' => WPDDL_TOOLSET_COMMON_RELPATH, 'ddl_listing_nonce' => wp_create_nonce('ddl_listing_nonce'), 'ddl_listing_show_posts_nonce' => wp_create_nonce('ddl_listing_show_posts_nonce'), 'ddl_listing_status' => isset($_GET['status']) && $_GET['status'] === 'trash' ? $_GET['status'] : 'publish', 'lib_path' => WPDDL_RES_RELPATH . '/js/external_libraries/', 'strings' => $this->get_listing_js_strings(), 'is_listing_page' => true, 'user_can_delete' => user_can_delete_layouts(), 'user_can_assign' => user_can_assign_layouts(), 'user_can_edit' => user_can_edit_layouts(), 'user_can_create' => user_can_create_layouts()); $wpddlayout->enqueue_scripts(array('dd-listing-page-main', 'ddl-post-types')); $wpddlayout->localize_script('dd-listing-page-main', 'DDLayout_settings', array('DDL_JS' => $localization_array, 'DDL_OPN' => self::change_layout_dialog_options_name(), 'items_per_page' => DDL_ITEMS_PER_PAGE)); $wpddlayout->enqueue_styles(array('views-pagination-style', 'dd-listing-page-style')); }
function preload_scripts() { global $wpddlayout; //speed up ajax calls sensibly wp_deregister_script('heartbeat'); wp_register_script('heartbeat', false); $wpddlayout->enqueue_scripts(array('jquery-ui-cell-sortable', 'jquery-ui-custom-sortable', 'jquery-ui-resizable', 'jquery-ui-tabs', 'wp-pointer', 'backbone', 'select2', 'toolset-utils', 'wp-pointer', 'wp-mediaelement', 'ddl-sanitize-html', 'ddl-sanitize-helper', 'ddl-post-types', 'ddl-editor-main', 'media_uploader_js', 'icl_media-manager-js')); $wpddlayout->localize_script('ddl-editor-main', 'icl_media_manager', array('only_img_allowed_here' => __("You can only use an image file here", 'ddl-layouts'))); $wpddlayout->localize_script('ddl-editor-main', 'DDLayout_settings', array('DDL_JS' => array('available_cell_types' => $wpddlayout->get_cell_types(), 'res_path' => WPDDL_RES_RELPATH, 'lib_path' => WPDDL_RES_RELPATH . '/js/external_libraries/', 'editor_lib_path' => WPDDL_GUI_RELPATH . "editor/js/", 'common_rel_path' => WPDDL_TOOLSET_COMMON_RELPATH, 'dialogs_lib_path' => WPDDL_GUI_RELPATH . "dialogs/js/", 'layout_id' => $this->layout_id, 'create_layout_nonce' => wp_create_nonce('create_layout_nonce'), 'save_layout_nonce' => wp_create_nonce('save_layout_nonce'), 'ddl-view-layout-nonce' => wp_create_nonce('ddl-view-layout-nonce'), 'ddl_show_all_posts_nonce' => wp_create_nonce('ddl_show_all_posts_nonce'), 'edit_layout_slug_nonce' => wp_create_nonce('edit_layout_slug_nonce'), 'compact_display_nonce' => wp_create_nonce('compact_display_nonce'), 'compact_display_mode' => $wpddlayout->get_option('compact_display'), 'DEBUG' => WPDDL_DEBUG, 'strings' => $this->get_editor_js_strings(), 'has_theme_sections' => $wpddlayout->has_theme_sections(), 'AMOUNT_OF_POSTS_TO_SHOW' => self::AMOUNT_OF_POSTS_TO_SHOW, 'is_css_enabled' => $wpddlayout->css_manager->is_css_possible(), 'current_framework' => $wpddlayout->frameworks_options_manager->get_current_framework(), 'cred_layout_css_text' => __('Layouts cell styling', 'ddl-layouts'), 'removed_cells' => $this->removed_cells, 'user_can_delete' => user_can_delete_layouts(), 'user_can_assign' => user_can_assign_layouts(), 'user_can_edit' => user_can_edit_layouts(), 'user_can_create' => user_can_create_layouts()), 'DDL_OPN' => WPDD_LayoutsListing::change_layout_dialog_options_name())); $wpddlayout->enqueue_cell_scripts(); }
function remove_layouts_loop_pagination_links() { if (user_can_create_layouts() === false) { $data = array('type' => 'capability', 'message' => __('You do not have permissions for that.', 'ddl-layouts')); wp_send_json_error($data); } if (!isset($_POST["wpnonce"]) || !wp_verify_nonce($_POST["wpnonce"], 'ddl_remove_layouts_loop_pagination_links')) { $data = array('type' => 'nonce', 'message' => __('Your security credentials have expired. Please reload the page to get new ones.', 'ddl-layouts')); wp_send_json_error($data); } if (function_exists('wpv_check_views_exists')) { $ddl_archive_loop_ids = wpv_check_views_exists('layouts-loop'); if ($ddl_archive_loop_ids) { $ddl_archive_loop_ids = array_map('esc_attr', $ddl_archive_loop_ids); $ddl_archive_loop_ids = array_map('trim', $ddl_archive_loop_ids); $ddl_archive_loop_ids = array_filter($ddl_archive_loop_ids, 'is_numeric'); $ddl_archive_loop_ids = array_map('intval', $ddl_archive_loop_ids); if (count($ddl_archive_loop_ids)) { global $wpdb; $final_post_content = "[wpv-filter-meta-html]\n[wpv-layout-meta-html]"; $wpdb->query($wpdb->prepare("UPDATE {$wpdb->posts}\n\t\t\t\t\t\t\tSET post_content = %s\n\t\t\t\t\t\t\tWHERE ID IN ('" . implode("','", $ddl_archive_loop_ids) . "')", $final_post_content)); } } $data = array('message' => __('Pagination links deleted.', 'ddl-layouts')); wp_send_json_success($data); } else { $data = array('type' => 'missing', 'message' => __('You need Views to perform this action.', 'ddl-layouts')); wp_send_json_error($data); } }