private function create_layout($name) { // @todo check with Ric to get a more handy class to create a new layout. // currently there is only (which I found) // - create_layout_auto(), which has a redirect // - create_layout_callback() for ajax only -> uses die() global $wpddlayout; if (!$this->needed_components_loaded()) { return false; } // permissions if (!current_user_can('manage_options') && WPDD_Layouts_Users_Profiles::user_can_create() && WPDD_Layouts_Users_Profiles::user_can_assign()) { return false; } $layout = WPDD_Layouts::create_layout(12, 'fluid'); // Define layout parameters $layout['type'] = 'fluid'; // layout_type $layout['cssframework'] = $wpddlayout->get_css_framework(); $layout['template'] = ''; $layout['parent'] = ''; $layout['name'] = $name; $args = array('post_title' => $name, 'post_content' => '', 'post_status' => 'publish', 'post_type' => WPDDL_LAYOUTS_POST_TYPE); $layout_id = wp_insert_post($args); // force layout object to take right ID // @see WPDD_Layouts::create_layout_callback() @ wpddl.class.php $layout_post = get_post($layout_id); $layout['id'] = $layout_id; $layout['slug'] = $layout_post->post_name; // update changes WPDD_Layouts::save_layout_settings($layout_id, $layout); return $layout_id; }
public function get_edit_link($plugin, $is_new, $type, $class, $post_id = null) { $edit_link = null; if ('layouts' === $plugin) { if ($is_new && WPDD_Layouts_Users_Profiles::user_can_create() && WPDD_Layouts_Users_Profiles::user_can_assign()) { $edit_link = wp_nonce_url(admin_url(sprintf('admin.php?page=dd_layouts_create_auto&type=%s&class=%s&post=%s', $type, $class, $post_id)), 'create_auto'); } else { if ($post_id > 0 && WPDD_Layouts_Users_Profiles::user_can_edit()) { // Layouts editor $edit_link = admin_url(sprintf('admin.php?page=dd_layouts_edit&layout_id=%s&action=edit', $post_id)); } } } else { if ('views' === $plugin && '404' != $type) { if ($is_new) { $edit_link = wp_nonce_url(admin_url(sprintf('admin.php?page=views_create_auto&type=%s&class=%s&post=%s', $type, $class, $post_id)), 'create_auto'); } else { if ($post_id > 0) { if ('archive' === $class) { // Views' WordPress Archive editor $edit_link = admin_url(sprintf('admin.php?page=view-archives-editor&view_id=%s', $post_id)); } else { if ('page' === $class) { // Views' Content Temaplate editor //$edit_link = admin_url( sprintf( 'post.php?action=edit&post=%s', $post_id ) ); $edit_link = esc_url_raw(add_query_arg(array('page' => WPV_CT_EDITOR_PAGE_NAME, 'ct_id' => esc_attr($post_id), 'action' => 'edit'), admin_url('admin.php'))); } } } } } } return $edit_link; }
public static function getInstance() { if (!self::$instance) { self::$instance = new WPDD_Layouts_Users_Profiles(); } return self::$instance; }
public function create_layout_auto() { // verify permissions if (!current_user_can('manage_options') && WPDD_Layouts_Users_Profiles::user_can_create() && WPDD_Layouts_Users_Profiles::user_can_assign()) { die(__('Untrusted user', 'ddl-layouts')); } // verify nonce check_admin_referer('create_auto'); // validate parameters $b_type = isset($_GET['type']) && preg_match('/^([-a-z0-9_]+)$/', $_GET['type']); $b_class = isset($_GET['class']) && preg_match('/^(archive|page)$/', $_GET['class']); $b_post_id = isset($_GET['post']) && (int) $_GET['post'] >= 0; // validate request if (!($b_type && $b_class && $b_post_id)) { die(__('Invalid parameters', 'ddl-layouts')); } // get parameters $type = $_GET['type']; $class = $_GET['class']; $post_id = (int) $_GET['post']; // enforce rules $b_page_archive = 'page' === $type && 'archive' === $class; if ($b_page_archive) { die(__('Not allowed', 'ddl-layouts')); } // prepare processing if ($post_id === 0) { $post_id = null; } $layout = null; $layout_id = 0; global $toolset_admin_bar_menu; $post_title = $toolset_admin_bar_menu->get_name_auto('layouts', $type, $class, $post_id); $title = sanitize_text_field(stripslashes_deep($post_title)); $taxonomy = get_taxonomy($type); $is_tax = $taxonomy !== false; $post_type_object = get_post_type_object($type); $is_cpt = $post_type_object != null; /* Create a new Layout */ global $wpddlayout; // Is there another Layout with the same name? $already_exists = $wpddlayout->does_layout_with_this_name_exist($title); if ($already_exists) { die(__('A layout with this name already exists. Please use a different name.', 'ddl-layouts')); } // Create a empty layout. No preset. // TODO: Pick the preset best suited (and check if Views is installed) $layout = $wpddlayout->create_layout(12, 'fluid'); // Define layout parameters $layout['type'] = 'fluid'; // layout_type $layout['cssframework'] = $wpddlayout->get_css_framework(); $layout['template'] = ''; $layout['parent'] = ''; $layout['name'] = $title; $args = array('post_title' => $title, 'post_content' => '', 'post_status' => 'publish', 'post_type' => WPDDL_LAYOUTS_POST_TYPE); $layout_id = wp_insert_post($args); // force layout object to take right ID // @see WPDD_Layouts::create_layout_callback() @ wpddl.class.php $layout_post = get_post($layout_id); $layout['id'] = $layout_id; $layout['slug'] = $layout_post->post_name; // assign layout if ('archive' === $class) { if (preg_match('/^(home-blog|search|author|year|month|day)$/', $type)) { // Create a new Layout for X archives /* assign Layout to X archives */ $layouts_wordpress_loop = sprintf('layouts_%s-page', $type); $wordpress_archive_loops = array($layouts_wordpress_loop); $wpddlayout->layout_post_loop_cell_manager->handle_archives_data_save($wordpress_archive_loops, $layout_id); } else { if ($is_tax) { // Create a new Layout for Y archives /* assign Layout to Y archives */ $layouts_taxonomy_loop = sprintf('layouts_taxonomy_loop_%s', $type); $wordpress_archive_loops = array($layouts_taxonomy_loop); $wpddlayout->layout_post_loop_cell_manager->handle_archives_data_save($wordpress_archive_loops, $layout_id); } else { if ($is_cpt) { // Create a new Layout for Z archives /* assign Layout to Z archives */ $layouts_cpt = sprintf('layouts_cpt_%s', $type); $wordpress_archive_loops = array($layouts_cpt); $wpddlayout->layout_post_loop_cell_manager->handle_archives_data_save($wordpress_archive_loops, $layout_id); } else { die(__('An unexpected error happened.', 'ddl-layouts')); } } } } else { if ('page' === $class) { if ('404' === $type) { // Create a new Layout for Error 404 page /* assign Layout to 404 page */ $wordpress_others_section = array('layouts_404_page'); $wpddlayout->layout_post_loop_cell_manager->handle_others_data_save($wordpress_others_section, $layout_id); } else { if ('page' === $type) { // Create a new Layout for 'Page Title' /* assign Layout to Page */ $posts = array($post_id); $wpddlayout->post_types_manager->update_post_meta_for_post_type($posts, $layout_id); } else { if ($is_cpt) { // Create a new Layout for Ys /* assign Layout to Y */ $post_types = array($type); $wpddlayout->post_types_manager->handle_post_type_data_save($layout_id, $post_types, $post_types); //$wpddlayout->post_types_manager->handle_set_option_and_bulk_at_once( $layout_id, $post_types, $post_types ); } else { die(__('An unexpected error happened.', 'ddl-layouts')); } } } } } // update changes WPDD_Layouts::save_layout_settings($layout_id, $layout); // redirect to editor (headers already sent) $edit_link = $toolset_admin_bar_menu->get_edit_link('layouts', false, $type, $class, $layout_id); $exit_string = '<script type="text/javascript">' . 'window.location = "' . $edit_link . '";' . '</script>'; exit($exit_string); }
function __construct() { $this->plugin_localization(); WPDDL_Layouts_WPML::getInstance(); WPDDL_ModuleManagerSupport::getInstance(); WDDL_ExtraModulesLoader::getInstance(); $this->ddl_caps = WPDD_Layouts_Users_Profiles::getInstance(); $this->registed_cells = new WPDD_registed_cell_types(); $this->layout_post_loop_cell_manager = new WPDD_layout_post_loop_cell_manager(); $this->registered_theme_sections = new WPDD_register_layout_theme_section(); $this->scripts_manager = WPDDL_scripts_manager::getInstance(); if (is_admin()) { $this->parents_options = new WPDDL_Options_Manager(self::PARENTS_OPTIONS); } $this->post_types_manager = new WPDD_Layouts_PostTypesManager(); $this->individual_assignment_manager = new WPDD_Layouts_IndividualAssignmentManager(); global $wpdd_gui_editor; $this->wpddl_init(); $this->css_manager = WPDD_Layouts_CSSManager::getInstance(); $this->frameworks_options_manager = WPDD_Layouts_CSSFrameworkOptions::getInstance(); $this->set_css_framework($this->frameworks_options_manager->get_current_framework()); add_action('wp_ajax_nopriv_' . WPDDL_LAYOUTS_CSS, array(&$this, 'handle_layout_css_from_db_print'), 10); add_action('init', array(&$this, 'init_listing_page'), 20); add_action('before_delete_post', array(&$this, 'before_delete_post_action')); add_action('add_attachment', array(&$this, 'add_attachment_action')); if (is_admin()) { // a little trick to have global $this available in post edit page upon construction add_action('init', array(&$this, 'init_create_layout_for_pages'), 20); $this->fix_up_views_slugs(); if ($this->layouts_editor_page) { new WPDD_GUI_DIALOGS(); } global $pagenow; $wpdd_gui_editor = new WPDD_GUI_EDITOR(); /**/ if (class_exists('WPDDL_Admin_Pages')) { WPDDL_Admin_Pages::getInstance(); } else { if (class_exists('WPDDL_Admin_Pages_Embedded')) { WPDDL_Admin_Pages_Embedded::getInstance(); } } if ($pagenow == 'plugins.php') { add_action('admin_enqueue_scripts', array($this, 'plugin_page_styles')); } if (isset($_GET['page']) && ($_GET['page'] == WPDDL_LAYOUTS_POST_TYPE || $_GET['page'] == 'dd_layout_theme_export' || $_GET['page'] == 'dd_layouts_edit')) { add_action('admin_enqueue_scripts', array($this, 'preload_styles')); add_action('admin_enqueue_scripts', array($this, 'preload_scripts')); } if (isset($_GET['page']) && $_GET['page'] == 'dd_tutorial_videos') { add_action('admin_enqueue_scripts', array($this, 'help_page_scripts')); } if (isset($_GET['in-iframe-for-layout']) && $_GET['in-iframe-for-layout'] == 1 && defined('CRED_FORMS_CUSTOM_POST_NAME') && $pagenow == 'post.php' && isset($_GET['post'])) { $post_id = $_GET['post']; $post = get_post($post_id); if ($post->post_type == CRED_FORMS_CUSTOM_POST_NAME) { add_action('admin_enqueue_scripts', array($this, 'cred_in_iframe_scripts')); } } if (isset($_GET['in-iframe-for-layout']) && $_GET['in-iframe-for-layout'] == 1 && defined('CRED_USER_FORMS_CUSTOM_POST_NAME') && $pagenow == 'post.php' && isset($_GET['post'])) { $post_id = $_GET['post']; $post = get_post($post_id); if ($post->post_type == CRED_USER_FORMS_CUSTOM_POST_NAME) { add_action('admin_enqueue_scripts', array($this, 'cred_user_in_iframe_scripts')); } } if (isset($_GET['in-iframe-for-layout']) && $_GET['in-iframe-for-layout'] == 1 && isset($_GET['page']) && ('views-editor' == $_GET['page'] || 'views-embedded' == $_GET['page'] || 'view-archives-embedded' == $_GET['page'] || 'view-archives-editor' == $_GET['page'])) { add_action('admin_enqueue_scripts', array($this, 'views_in_iframe_scripts')); } if (isset($_GET['in-iframe-for-layout']) && '1' == $_GET['in-iframe-for-layout']) { wp_deregister_script('heartbeat'); remove_action('wp_head', 'print_emoji_detection_script', 7); remove_action('wp_print_styles', 'print_emoji_styles'); } add_action('wp_ajax_ddl_create_layout', array($this, 'create_layout_callback')); add_action('wp_ajax_ddl_dismiss_template_message', array($this, 'ddl_dismiss_template_message')); /** * add extra debug information */ add_filter('icl_get_extra_debug_info', array($this, 'add_extra_debug_information')); add_action('wpml_register_string_packages', array($this, 'register_all_strings_for_translation'), 10, 0); add_action('admin_enqueue_scripts', array($this, 'enqueue_toolset_common_styles')); } else { // add_action('wp_head', array(&$this,'handle_layout_css_fe')); if (isset($_GET['ddl_style'])) { header('Content-Type:text/css'); $this->wpddl_frontent_styles($_GET['ddl_style']); die; } // Assign post layout for post create from front-end add_action('wp_enqueue_scripts', array($this, 'load_frontend_js')); add_action('wp_enqueue_scripts', array($this, 'load_frontend_css')); //place layout edit link in last position add_action('get_layout_id_for_render', array(&$this, 'get_layout_id_for_render_callback'), 888, 2); // @see class-toolset-admin-bar-menu.php //add_action( 'admin_bar_menu', array($this, 'print_layout_edit_link'), 999 ); add_action('wp_enqueue_scripts', array($this, 'enqueue_toolset_common_styles')); /** * get cache singleton */ WPDD_Layouts_Cache_Singleton::getInstance(); } }
public static function wpcf_process_change_role_caps_ajax() { if (!current_user_can('manage_options')) { _e('There are security problems. You do not have permissions.', 'wpcf-access'); die; } if (!isset($_POST['wpnonce']) || !wp_verify_nonce($_POST['wpnonce'], 'wpcf-access-error-pages')) { die('verification failed'); } $role = sanitize_text_field($_POST['role']); $caps = ''; if (isset($_POST['caps'])) { $caps = array_map('sanitize_text_field', $_POST['caps']); } TAccess_Loader::load('CLASS/Admin_Edit'); $model = TAccess_Loader::get('MODEL/Access'); $default_caps = getDefaultCaps(); $default_wordpress_caps = $default_caps[10]; $access_roles = $model->getAccessRoles(); $wocommerce_caps = get_woocommerce_caps(); $wpml_caps_list = get_wpml_caps(); $custom_caps = get_option('wpcf_access_custom_caps'); //$toolset_caps_list = get_toolset_caps(); $role_data = get_role($role); for ($i = 0, $caps_limit = count($default_wordpress_caps); $i < $caps_limit; $i++) { if (isset($access_roles[$role]['caps'][$default_wordpress_caps[$i]])) { unset($access_roles[$role]['caps'][$default_wordpress_caps[$i]]); $role_data->remove_cap($default_wordpress_caps[$i]); } } foreach ($wocommerce_caps as $cap => $cap_info) { if (isset($access_roles[$role]['caps'][$cap])) { unset($access_roles[$role]['caps'][$cap]); $role_data->remove_cap($cap); } } foreach ($wpml_caps_list as $cap => $cap_info) { if (isset($access_roles[$role]['caps'][$cap])) { unset($access_roles[$role]['caps'][$cap]); $role_data->remove_cap($cap); } } if (is_array($custom_caps)) { foreach ($custom_caps as $cap => $cap_info) { if (isset($access_roles[$role]['caps'][$cap])) { unset($access_roles[$role]['caps'][$cap]); $role_data->remove_cap($cap); } } } if (class_exists('WPDD_Layouts_Users_Profiles')) { foreach (WPDD_Layouts_Users_Profiles::ddl_get_capabilities() as $cap => $cap_info) { if (isset($access_roles[$role]['caps'][$cap])) { unset($access_roles[$role]['caps'][$cap]); $role_data->remove_cap($cap); } } } $access_caps = array('access_change_post_group' => __('Select access group for content', 'wpcf-access'), 'access_create_new_group' => __('Create new access groups', 'wpcf-access')); foreach ($access_caps as $cap => $cap_info) { if (isset($access_roles[$role]['caps'][$cap])) { unset($access_roles[$role]['caps'][$cap]); $role_data->remove_cap($cap); } } /* foreach ($toolset_caps_list as $cap => $cap_info){ if ( isset( $access_roles[$role]['caps'][$cap] ) ){ unset( $access_roles[$role]['caps'][$cap] ); $role_data->remove_cap($cap); } } */ for ($i = 0, $caps_limit = count($caps); $i < $caps_limit; $i++) { $cap = str_replace('cap_', '', $caps[$i]); $access_roles[$role]['caps'][$cap] = true; $role_data->add_cap($cap); } $model->updateAccessRoles($access_roles); die; }
function wpcf_access_layouts_capabilities($data) { if (class_exists('WPDD_Layouts_Users_Profiles')) { $wp_roles['label'] = __('Layouts capabilities', 'wpcf-access'); $wp_roles['capabilities'] = WPDD_Layouts_Users_Profiles::ddl_get_capabilities(); $data[] = $wp_roles; } return $data; }
function user_can_delete_layouts() { return WPDD_Layouts_Users_Profiles::user_can_delete(); }
/** * Adds items to admin menu. * * @param array $menu array of menu items * @param string $parent_slug menu slug, if exist item is added as submenu * * @return void function do not return anything * */ public function add_to_menu($menu, $parent_slug = null) { foreach ($menu as $menu_slug => $data) { $slug = null; if (empty($parent_slug)) { $slug = add_menu_page($data['title'], isset($data['menu']) ? $data['menu'] : $data['title'], WPDD_Layouts_Users_Profiles::get_cap_for_page($menu_slug), $menu_slug, isset($data['function']) ? $data['function'] : null); } else { $slug = add_submenu_page($parent_slug, $data['title'], isset($data['menu']) ? $data['menu'] : $data['title'], WPDD_Layouts_Users_Profiles::get_cap_for_page($menu_slug), $menu_slug, isset($data['function']) ? $data['function'] : null); } /** * add load hook if is defined */ if (!empty($slug) && isset($data['load_hook'])) { add_action('load-' . $slug, $data['load_hook']); } /** * add subpages */ if (isset($data['subpages'])) { $this->add_to_menu($data['subpages'], $menu_slug); } } }