/** * Do things like register/enqueue scripts and stylesheets * * @since 2.0 */ public function __construct() { add_shortcode('pods-content', array($this, 'shortcode')); $args = array('label' => 'Pod Pages', 'labels' => array('singular_name' => 'Pod Page'), 'public' => false, 'can_export' => false, 'show_ui' => true, 'show_in_menu' => false, 'query_var' => false, 'rewrite' => false, 'has_archive' => false, 'hierarchical' => false, 'supports' => array('title', 'author', 'revisions'), 'menu_icon' => PODS_URL . 'ui/images/icon16.png'); if (!pods_is_admin()) { $args['capability_type'] = 'pods_page'; } $args = PodsInit::object_label_fix($args, 'post_type'); register_post_type($this->object_type, apply_filters('pods_internal_register_post_type_object_page', $args)); add_filter('post_type_link', array($this, 'post_type_link'), 10, 2); if (!is_admin()) { add_action('load_textdomain', array($this, 'page_check'), 12); } else { add_filter('post_updated_messages', array($this, 'setup_updated_messages'), 10, 1); add_action('dbx_post_advanced', array($this, 'edit_page_form'), 10); add_action('pods_meta_groups', array($this, 'add_meta_boxes')); add_filter('get_post_metadata', array($this, 'get_meta'), 10, 4); add_filter('update_post_metadata', array($this, 'save_meta'), 10, 4); add_action('pods_meta_save_pre_post__pods_page', array($this, 'fix_filters'), 10, 5); add_action('post_updated', array($this, 'clear_cache'), 10, 3); add_action('delete_post', array($this, 'clear_cache'), 10, 1); add_filter('post_row_actions', array($this, 'remove_row_actions'), 10, 2); add_filter('bulk_actions-edit-' . $this->object_type, array($this, 'remove_bulk_actions')); add_filter('builder_layout_filter_non_layout_post_types', array($this, 'disable_builder_layout')); } }
/** * Get list of components available * * @since 2.0 */ public function get_components() { $components = pods_transient_get('pods_components'); if (1 == pods_var('pods_debug_components', 'get', 0) && pods_is_admin(array('pods'))) { $components = array(); } if (PodsInit::$version != PODS_VERSION || !is_array($components) || empty($components) || is_admin() && isset($_GET['page']) && 'pods-components' == $_GET['page'] && 1 !== pods_transient_get('pods_components_refresh')) { do_action('pods_components_get'); $component_dir = @opendir(untrailingslashit($this->components_dir)); $component_files = array(); if (false !== $component_dir) { while (false !== ($file = readdir($component_dir))) { if ('.' == substr($file, 0, 1)) { continue; } elseif (is_dir($this->components_dir . $file)) { $component_subdir = @opendir($this->components_dir . $file); if ($component_subdir) { while (false !== ($subfile = readdir($component_subdir))) { if ('.' == substr($subfile, 0, 1)) { continue; } elseif ('.php' == substr($subfile, -4)) { $component_files[] = str_replace('\\', '/', $file . '/' . $subfile); } } closedir($component_subdir); } } elseif ('.php' == substr($file, -4)) { $component_files[] = $file; } } closedir($component_dir); } $default_headers = array('ID' => 'ID', 'Name' => 'Name', 'ShortName' => 'Short Name', 'PluginName' => 'Plugin Name', 'ComponentName' => 'Component Name', 'URI' => 'URI', 'MenuName' => 'Menu Name', 'MenuPage' => 'Menu Page', 'MenuAddPage' => 'Menu Add Page', 'MustUse' => 'Must Use', 'Description' => 'Description', 'Version' => 'Version', 'Category' => 'Category', 'Author' => 'Author', 'AuthorURI' => 'Author URI', 'Class' => 'Class', 'Hide' => 'Hide', 'PluginDependency' => 'Plugin Dependency', 'ThemeDependency' => 'Theme Dependency', 'DeveloperMode' => 'Developer Mode', 'TablelessMode' => 'Tableless Mode', 'Capability' => 'Capability', 'Plugin' => 'Plugin'); $component_files = apply_filters('pods_components_register', $component_files); $components = array(); foreach ($component_files as $component_file) { $external = false; if (is_array($component_file) && isset($component_file['File'])) { $component = $component_file = $component_file['File']; $external = true; } else { $component = $this->components_dir . $component_file; } if (!is_readable($component)) { continue; } $component_data = get_file_data($component, $default_headers, 'pods_component'); if (empty($component_data['Name']) && empty($component_data['ComponentName']) && empty($component_data['PluginName']) || 'yes' == $component_data['Hide']) { continue; } if (isset($component_data['Plugin']) && pods_is_plugin_active($component_data['Plugin'])) { continue; } if (empty($component_data['Name'])) { if (!empty($component_data['ComponentName'])) { $component_data['Name'] = $component_data['ComponentName']; } elseif (!empty($component_data['PluginName'])) { $component_data['Name'] = $component_data['PluginName']; } } if (empty($component_data['ShortName'])) { $component_data['ShortName'] = $component_data['Name']; } if (empty($component_data['MenuName'])) { $component_data['MenuName'] = $component_data['Name']; } if (empty($component_data['Class'])) { $component_data['Class'] = 'Pods_' . pods_clean_name(basename($component, '.php'), false); } if (empty($component_data['ID'])) { $component_data['ID'] = $component_data['Name']; } $component_data['ID'] = sanitize_title($component_data['ID']); if ('on' == strtolower($component_data['DeveloperMode']) || 1 == $component_data['DeveloperMode']) { $component_data['DeveloperMode'] = true; } else { $component_data['DeveloperMode'] = false; } if ('on' == strtolower($component_data['TablelessMode']) || 1 == $component_data['TablelessMode']) { $component_data['TablelessMode'] = true; } else { $component_data['TablelessMode'] = false; } $component_data['External'] = (bool) $external; if ('on' == strtolower($component_data['MustUse']) || '1' == $component_data['MustUse']) { $component_data['MustUse'] = true; } elseif ('off' == strtolower($component_data['MustUse']) || '0' == $component_data['MustUse']) { $component_data['MustUse'] = false; } else { $component_data['MustUse'] = $component_data['External']; } $component_data['File'] = $component_file; $components[$component_data['ID']] = $component_data; } ksort($components); pods_transient_set('pods_components_refresh', 1, 60 * 60 * 12); pods_transient_set('pods_components', $components); } if (1 == pods_var('pods_debug_components', 'get', 0) && pods_is_admin(array('pods'))) { pods_debug($components); } $this->components = $components; return $this->components; }
/** * Check if a user has permission to be doing something based on standard permission options * * @param array $options * * @return bool Whether the user has permissions * * @since 2.0.5 */ function pods_permission($options) { global $current_user; get_currentuserinfo(); $permission = false; if (isset($options['options'])) { $options = $options['options']; } if (pods_is_admin()) { $permission = true; } elseif (0 == pods_var('restrict_role', $options, 0) && 0 == pods_var('restrict_capability', $options, 0) && 0 == pods_var('admin_only', $options, 0)) { $permission = true; } if (!$permission && 1 == pods_var('restrict_role', $options, 0)) { $roles = pods_var('roles_allowed', $options); if (!is_array($roles)) { $roles = explode(',', $roles); } $roles = array_unique(array_filter($roles)); foreach ($roles as $role) { if (is_user_logged_in() && in_array($role, $current_user->roles)) { $permission = true; break; } } } if (!$permission && 1 == pods_var('restrict_capability', $options, 0)) { $capabilities = pods_var('capability_allowed', $options); if (!is_array($capabilities)) { $capabilities = explode(',', $capabilities); } $capabilities = array_unique(array_filter($capabilities)); foreach ($capabilities as $capability) { $must_have_capabilities = explode('&&', $capability); $must_have_capabilities = array_unique(array_filter($must_have_capabilities)); $must_have_permission = true; foreach ($must_have_capabilities as $must_have_capability) { if (!current_user_can($must_have_capability)) { $must_have_permission = false; break; } } if ($must_have_permission && is_user_logged_in()) { $permission = true; break; } } } return $permission; }
public function restricted($action = 'edit', $row = null) { $restricted = false; $restrict = array(); if (isset($this->restrict[$action])) { $restrict = (array) $this->restrict[$action]; } // @todo Build 'edit', 'duplicate', 'delete' action support for 'where' which runs another find() query /*if ( !in_array( $action, array( 'manage', 'reorder' ) ) ) { $where = pods_var_raw( $action, $this->where, null, null, true ); if ( !empty( $where ) ) { $restricted = true; $old_where = $this->where[ $action ]; $id = $this->row[ $this->sql[ 'field_id' ] ]; if ( is_array( $where ) ) { if ( 'OR' == pods_var( 'relation', $where ) ) $where = array( $where ); $where[] = "`t`.`" . $this->sql[ 'field_id' ] . "` = " . (int) $id; } else $where = "( {$where} ) AND `t`.`" . $this->sql[ 'field_id' ] . "` = " . (int) $id; $this->where[ $action ] = $where; $data = false; //$data = $this->get_data(); $this->where[ $action ] = $old_where; if ( empty( $data ) ) $restricted = true; } }*/ $author_restrict = false; if (!empty($this->restrict['author_restrict']) && $restrict === $this->restrict['author_restrict']) { $restricted = false; $author_restrict = true; if (is_object($this->pod)) { $restricted = true; if ('settings' == $this->pod->pod_data['type'] && 'add' == $action) { $action = 'edit'; } if (pods_is_admin(array('pods', 'pods_content'))) { $restricted = false; } elseif ('manage' == $action) { if (!in_array('edit', $this->actions_disabled) && current_user_can('pods_edit_' . $this->pod->pod) && current_user_can('pods_edit_others_' . $this->pod->pod)) { $restricted = false; } elseif (!in_array('delete', $this->actions_disabled) && current_user_can('pods_delete_' . $this->pod->pod) && current_user_can('pods_delete_others_' . $this->pod->pod)) { $restricted = false; } elseif (current_user_can('pods_' . $action . '_' . $this->pod->pod) && current_user_can('pods_' . $action . '_others_' . $this->pod->pod)) { $restricted = false; } } elseif (current_user_can('pods_' . $action . '_' . $this->pod->pod) && current_user_can('pods_' . $action . '_others_' . $this->pod->pod)) { $restricted = false; } } /* @todo determine proper logic for non-pods capabilities else { $restricted = true; if ( pods_is_admin( array( 'pods', 'pods_content' ) ) ) $restricted = false; elseif ( current_user_can( 'pods_' . $action . '_others_' . $_tbd ) ) $restricted = false; }*/ } if ($restricted && !empty($restrict)) { $relation = strtoupper(trim(pods_var('relation', $restrict, 'AND', null, true))); if ('AND' != $relation) { $relation = 'OR'; } $okay = true; foreach ($restrict as $field => $match) { if ('relation' == $field) { continue; } if (is_array($match)) { $match_okay = true; $match_relation = strtoupper(trim(pods_var('relation', $match, 'OR', null, true))); if ('AND' != $match_relation) { $match_relation = 'OR'; } foreach ($match as $the_field => $the_match) { if ('relation' == $the_field) { continue; } $value = null; if (is_object($this->pod)) { $value = $this->pod->field($the_match, true); } else { if (empty($row)) { $row = $this->row; } if (isset($row[$the_match])) { if (is_array($row[$the_match])) { if (false !== strpos($the_match, '.')) { $the_matches = explode('.', $the_match); $value = $row[$the_match]; foreach ($the_matches as $m) { if (is_array($value) && isset($value[$m])) { $value = $value[$m]; } else { $value = null; break; } } } } else { $value = $row[$the_match]; } } } if (is_array($value)) { if (!in_array($the_match, $value)) { $match_okay = false; } elseif ('OR' == $match_relation) { $match_okay = true; break; } } elseif ($value == $the_match) { $match_okay = false; } elseif ('OR' == $match_relation) { $match_okay = true; break; } } if (!$match_okay) { $okay = false; } if ('OR' == $relation) { $okay = true; break; } } else { $value = null; if (is_object($this->pod)) { $value = $this->pod->field($match, true); } else { if (empty($row)) { $row = $this->row; } if (isset($row[$match])) { if (is_array($row[$match])) { if (false !== strpos($match, '.')) { $matches = explode('.', $match); $value = $row[$match]; foreach ($matches as $m) { if (is_array($value) && isset($value[$m])) { $value = $value[$m]; } else { $value = null; break; } } } } else { $value = $row[$match]; } } } if (is_array($value)) { if (!in_array($match, $value)) { $okay = false; } elseif ('OR' == $relation) { $okay = true; break; } } elseif ($value != $match) { $okay = false; } elseif ('OR' == $relation) { $okay = true; break; } } } if (!empty($author_restrict)) { if (is_object($this->pod) && 'manage' == $action) { if (!in_array('edit', $this->actions_disabled) && !current_user_can('pods_edit_' . $this->pod->pod) && !in_array('delete', $this->actions_disabled) && !current_user_can('pods_delete_' . $this->pod->pod)) { $okay = false; } } if (is_object($this->pod) && !current_user_can('pods_' . $action . '_' . $this->pod->pod)) { $okay = false; } /* @todo determine proper logic for non-pods capabilities elseif ( !current_user_can( 'pods_' . $action . '_' . $_tbd ) ) $okay = false;*/ if (!$okay && !empty($row)) { foreach ($this->restrict['author_restrict'] as $key => $val) { $author_restricted = $this->get_field($key); if (!empty($author_restricted)) { if (!is_array($author_restricted)) { $author_restricted = (array) $author_restricted; } if (is_array($val)) { foreach ($val as $v) { if (in_array($v, $author_restricted)) { $okay = true; } } } elseif (in_array($val, $author_restricted)) { $okay = true; } } } } } if ($okay) { $restricted = false; } } if (isset($this->actions_custom[$action]) && is_array($this->actions_custom[$action]) && isset($this->actions_custom[$action]['restrict_callback']) && is_callable($this->actions_custom[$action]['restrict_callback'])) { $restricted = call_user_func($this->actions_custom[$action]['restrict_callback'], $restricted, $restrict, $action, $row, $this); } $restricted = $this->do_hook('restricted_' . $action, $restricted, $restrict, $action, $row); return $restricted; }
/** * Handle ajax calls for the administration */ public function admin_ajax() { if (false === headers_sent()) { pods_session_start(); header('Content-Type: text/html; charset=' . get_bloginfo('charset')); } // Sanitize input $params = pods_unslash((array) $_POST); foreach ($params as $key => $value) { if ('action' == $key) { continue; } // Fixup $_POST data $_POST[str_replace('_podsfix_', '', $key)] = $_POST[$key]; // Fixup $params with unslashed data $params[str_replace('_podsfix_', '', $key)] = $value; // Unset the _podsfix_* keys unset($params[$key]); } $params = (object) $params; $methods = array('add_pod' => array('priv' => true), 'save_pod' => array('priv' => true), 'load_sister_fields' => array('priv' => true), 'process_form' => array('custom_nonce' => true), 'upgrade' => array('priv' => true), 'migrate' => array('priv' => true)); $methods = apply_filters('pods_admin_ajax_methods', $methods, $this); if (!isset($params->method) || !isset($methods[$params->method])) { pods_error('Invalid AJAX request', $this); } $defaults = array('priv' => null, 'name' => $params->method, 'custom_nonce' => null); $method = (object) array_merge($defaults, (array) $methods[$params->method]); if (true !== $method->custom_nonce && (!isset($params->_wpnonce) || false === wp_verify_nonce($params->_wpnonce, 'pods-' . $params->method))) { pods_error(__('Unauthorized request', 'pods'), $this); } // Cleaning up $params unset($params->action); unset($params->method); if (true !== $method->custom_nonce) { unset($params->_wpnonce); } // Check permissions (convert to array to support multiple) if (!empty($method->priv) && !pods_is_admin(array('pods')) && true !== $method->priv && !pods_is_admin($method->priv)) { pods_error(__('Access denied', 'pods'), $this); } $params->method = $method->name; $params = apply_filters('pods_api_' . $method->name, $params, $method); $api = pods_api(); if ('upgrade' == $method->name) { $output = (string) pods_upgrade($params->version)->ajax($params); } elseif ('migrate' == $method->name) { $output = (string) apply_filters('pods_api_migrate_run', $params); } else { if (!method_exists($api, $method->name)) { pods_error('API method does not exist', $this); } elseif ('save_pod' == $method->name) { if (isset($params->field_data_json) && is_array($params->field_data_json)) { $params->fields = $params->field_data_json; unset($params->field_data_json); foreach ($params->fields as $k => $v) { if (empty($v)) { unset($params->fields[$k]); } elseif (!is_array($v)) { $params->fields[$k] = (array) @json_decode($v, true); } } } } // Dynamically call the API method $params = (array) $params; $output = call_user_func(array($api, $method->name), $params); } // Output in json format if (false !== $output) { if (is_array($output) || is_object($output)) { wp_send_json($output); } else { echo $output; } } else { pods_error('There was a problem with your request.'); } die; // KBAI! }
<?php } ?> </div> <?php } ?> </div> <!-- /#minor-publishing --> <?php } ?> <div id="major-publishing-actions"> <?php if (pods_is_admin(array('pods', 'pods_delete_' . $pod->pod)) && null !== $pod->id() && !$duplicate && !in_array('delete', $obj->actions_disabled) && !in_array('delete', $obj->actions_hidden)) { ?> <div id="delete-action"> <a class="submitdelete deletion" href="<?php echo pods_var_update(array('action' => 'delete')); ?> " onclick="return confirm('You are about to permanently delete this item\n Choose \'Cancel\' to stop, \'OK\' to delete.');"><?php _e('Delete', 'pods'); ?> </a> </div> <!-- /#delete-action --> <?php } ?>
/** * @static * * Do a query on the database * * @param string|array $sql The SQL to execute * @param string $error Error to throw on problems * @param null $results_error (optional) * @param null $no_results_error (optional) * * @return array|bool|mixed|null|void Result of the query * * @since 2.0 */ public static function query($sql, $error = 'Database Error', $results_error = null, $no_results_error = null) { /** * @var $wpdb wpdb */ global $wpdb; if ($wpdb->show_errors) { self::$display_errors = true; } $display_errors = self::$display_errors; if (is_object($error)) { if (isset($error->display_errors) && false === $error->display_errors) { $display_errors = false; } $error = 'Database Error'; } elseif (is_bool($error)) { $display_errors = $error; if (false !== $error) { $error = 'Database Error'; } } $params = (object) array('sql' => $sql, 'error' => $error, 'results_error' => $results_error, 'no_results_error' => $no_results_error, 'display_errors' => $display_errors); // Handle Preparations of Values (sprintf format) if (is_array($sql)) { if (isset($sql[0]) && 1 < count($sql)) { if (2 == count($sql)) { if (!is_array($sql[1])) { $sql[1] = array($sql[1]); } $params->sql = self::prepare($sql[0], $sql[1]); } elseif (3 == count($sql)) { $params->sql = self::prepare($sql[0], array($sql[1], $sql[2])); } else { $params->sql = self::prepare($sql[0], array($sql[1], $sql[2], $sql[3])); } } else { $params = array_merge($params, $sql); } if (1 == pods_var('pods_debug_sql_all', 'get', 0) && pods_is_admin(array('pods'))) { echo '<textarea cols="100" rows="24">' . str_replace(array('@wp_users', '@wp_'), array($wpdb->users, $wpdb->prefix), $params->sql) . '</textarea>'; } } $params->sql = trim($params->sql); // Run Query $params->sql = self::do_hook('query', $params->sql, $params); $result = $wpdb->query($params->sql); $result = self::do_hook('query_result', $result, $params); if (false === $result && !empty($params->error) && !empty($wpdb->last_error)) { return pods_error("{$params->error}; SQL: {$params->sql}; Response: {$wpdb->last_error}", $params->display_errors); } if ('INSERT' == strtoupper(substr($params->sql, 0, 6)) || 'REPLACE' == strtoupper(substr($params->sql, 0, 7))) { $result = $wpdb->insert_id; } elseif (preg_match('/^[\\s\\r\\n\\(]*SELECT/', strtoupper($params->sql))) { $result = (array) $wpdb->last_result; if (!empty($result) && !empty($params->results_error)) { return pods_error($params->results_error, $params->display_errors); } elseif (empty($result) && !empty($params->no_results_error)) { return pods_error($params->no_results_error, $params->display_errors); } } return $result; }
/** * @static * * @param string $key Key for the cache * @param string $cache_mode (optional) Decides the caching method to use for the view. * @param string $group (optional) Set the group of the value. * @param string $callback (optional) Callback function to run to set the value if not cached. * * @return bool|mixed|null|void * * @since 2.0 */ public static function get($key, $cache_mode = 'cache', $group = '', $callback = null) { $object_cache = false; if (isset($GLOBALS['wp_object_cache']) && is_object($GLOBALS['wp_object_cache'])) { $object_cache = true; } if (!in_array($cache_mode, self::$cache_modes)) { $cache_mode = 'cache'; } $group_key = 'pods_'; if (!empty($group)) { $group_key = $group . '_'; } $original_key = $key; // Get proper cache key $key = self::get_key($key, $group_key); $value = null; $called = false; $pods_nocache = pods_var_raw('pods_nocache'); $nocache = array(); if (pods_is_admin() && null !== $pods_nocache) { if (1 < strlen($pods_nocache)) { $nocache = explode(',', $pods_nocache); } else { $nocache = self::$cache_modes; } } if (apply_filters('pods_view_cache_alt_get', false, $cache_mode, $group_key . $key, $original_key, $group)) { $value = apply_filters('pods_view_cache_alt_get_value', $value, $cache_mode, $group_key . $key, $original_key, $group); } elseif ('transient' == $cache_mode && !in_array($cache_mode, $nocache)) { $value = get_transient($group_key . $key); } elseif ('site-transient' == $cache_mode && !in_array($cache_mode, $nocache)) { $value = get_site_transient($group_key . $key); } elseif ('cache' == $cache_mode && $object_cache && !in_array($cache_mode, $nocache)) { $value = wp_cache_get($key, empty($group) ? 'pods_view' : $group); } elseif ('option-cache' == $cache_mode && !in_array($cache_mode, $nocache)) { global $_wp_using_ext_object_cache; $pre = apply_filters('pre_transient_' . $key, false); if (false !== $pre) { $value = $pre; } elseif ($_wp_using_ext_object_cache) { $value = wp_cache_get($key, empty($group) ? 'pods_option_cache' : $group); $timeout = wp_cache_get('_timeout_' . $key, empty($group) ? 'pods_option_cache' : $group); if (!empty($timeout) && $timeout < time()) { if (is_callable($callback)) { // Callback function should do it's own set/update for cache $callback_value = call_user_func($callback, $original_key, $group, $cache_mode); if (null !== $callback_value && false !== $callback_value) { $value = $callback_value; } $called = true; } else { $value = false; wp_cache_delete($key, empty($group) ? 'pods_option_cache' : $group); wp_cache_delete('_timeout_' . $key, empty($group) ? 'pods_option_cache' : $group); } } } else { $transient_option = '_pods_option_' . $key; $transient_timeout = '_pods_option_timeout_' . $key; $value = get_option($transient_option); $timeout = get_option($transient_timeout); if (!empty($timeout) && $timeout < time()) { if (is_callable($callback)) { // Callback function should do it's own set/update for cache $callback_value = call_user_func($callback, $original_key, $group, $cache_mode); if (null !== $callback_value && false !== $callback_value) { $value = $callback_value; } $called = true; } else { $value = false; delete_option($transient_option); delete_option($transient_timeout); } } } if (false !== $value) { $value = apply_filters('transient_' . $key, $value); } } else { $value = false; } if (false === $value && is_callable($callback) && !$called) { // Callback function should do it's own set/update for cache $callback_value = call_user_func($callback, $original_key, $group, $cache_mode); if (null !== $callback_value && false !== $callback_value) { $value = $callback_value; } } $value = apply_filters('pods_view_get_' . $cache_mode, $value, $original_key, $group); return $value; }
/** * * Generate UI for Data Management * * @param mixed $options Array or String containing Pod or Options to be used * @param bool $amend Whether to amend the default UI options or replace entirely * * @return PodsUI|void UI object or void if custom UI used * * @since 2.3.10 */ public function ui($options = null, $amend = false) { $num = ''; if (empty($options)) { $options = array(); } else { $num = pods_var('num', $options, ''); if (empty($num)) { $num = ''; } } if ($this->id() != pods_var('id' . $num, 'get', null, null, true)) { $this->fetch(pods_var('id' . $num, 'get', null, null, true)); } if (!empty($options) && !$amend) { $this->ui = $options; return pods_ui($this); } elseif (!empty($options) || 'custom' != pods_var('ui_style', $this->pod_data['options'], 'post_type', null, true)) { $actions_enabled = pods_var_raw('ui_actions_enabled', $this->pod_data['options']); if (!empty($actions_enabled)) { $actions_enabled = (array) $actions_enabled; } else { $actions_enabled = array(); } $available_actions = array('add', 'edit', 'duplicate', 'delete', 'reorder', 'export'); if (!empty($actions_enabled)) { $actions_disabled = array('view' => 'view'); foreach ($available_actions as $action) { if (!in_array($action, $actions_enabled)) { $actions_disabled[$action] = $action; } } } else { $actions_disabled = array('duplicate' => 'duplicate', 'view' => 'view', 'export' => 'export'); if (1 == pods_var('ui_export', $this->pod_data['options'], 0)) { unset($actions_disabled['export']); } } if (empty($options)) { $author_restrict = false; if (isset($this->fields['author']) && 'pick' == $this->fields['author']['type'] && 'user' == $this->fields['author']['pick_object']) { $author_restrict = 'author.ID'; } if (!pods_is_admin(array('pods', 'pods_content'))) { if (!current_user_can('pods_add_' . $this->pod)) { $actions_disabled['add'] = 'add'; if ('add' == pods_var('action' . $num, 'get')) { $_GET['action' . $num] = 'manage'; } } if (!$author_restrict && !current_user_can('pods_edit_' . $this->pod) && !current_user_can('pods_edit_others_' . $this->pod)) { $actions_disabled['edit'] = 'edit'; } if (!$author_restrict && !current_user_can('pods_delete_' . $this->pod) && !current_user_can('pods_delete_others_' . $this->pod)) { $actions_disabled['delete'] = 'delete'; } if (!current_user_can('pods_reorder_' . $this->pod)) { $actions_disabled['reorder'] = 'reorder'; } if (!current_user_can('pods_export_' . $this->pod)) { $actions_disabled['export'] = 'export'; } } } $_GET['action' . $num] = pods_var('action' . $num, 'get', pods_var('action', $options, 'manage')); $index = $this->pod_data['field_id']; $label = __('ID', 'pods'); if (isset($this->pod_data['fields'][$this->pod_data['field_index']])) { $index = $this->pod_data['field_index']; $label = $this->pod_data['fields'][$this->pod_data['field_index']]; } $manage = array($index => $label); if (isset($this->pod_data['fields']['modified'])) { $manage['modified'] = $this->pod_data['fields']['modified']['label']; } $manage_fields = pods_var_raw('ui_fields_manage', $this->pod_data['options']); if (!empty($manage_fields)) { $manage_new = array(); foreach ($manage_fields as $manage_field) { if (isset($this->pod_data['fields'][$manage_field])) { $manage_new[$manage_field] = $this->pod_data['fields'][$manage_field]; } elseif (isset($this->pod_data['object_fields'][$manage_field])) { $manage_new[$manage_field] = $this->pod_data['object_fields'][$manage_field]; } elseif ($manage_field == $this->pod_data['field_id']) { $field = array('name' => $manage_field, 'label' => 'ID', 'type' => 'number', 'width' => '8%'); $manage_new[$manage_field] = PodsForm::field_setup($field, null, $field['type']); } } if (!empty($manage_new)) { $manage = $manage_new; } } $manage = apply_filters('pods_admin_ui_fields_' . $this->pod, apply_filters('pods_admin_ui_fields', $manage, $this->pod, $this), $this->pod, $this); $icon = pods_var_raw('ui_icon', $this->pod_data['options']); if (!empty($icon)) { $icon = pods_image_url($icon, '32x32'); } $filters = pods_var_raw('ui_filters', $this->pod_data['options']); if (!empty($filters)) { $filters_new = array(); foreach ($filters as $filter_field) { if (isset($this->pod_data['fields'][$filter_field])) { $filters_new[$filter_field] = $this->pod_data['fields'][$filter_field]; } elseif (isset($this->pod_data['object_fields'][$filter_field])) { $filters_new[$filter_field] = $this->pod_data['object_fields'][$filter_field]; } } $filters = $filters_new; } $ui = array('fields' => array('manage' => $manage, 'add' => $this->pod_data['fields'], 'edit' => $this->pod_data['fields'], 'duplicate' => $this->pod_data['fields']), 'icon' => $icon, 'actions_disabled' => $actions_disabled); if (!empty($filters)) { $ui['fields']['search'] = $filters; $ui['filters'] = array_keys($filters); $ui['filters_enhanced'] = true; } $reorder_field = pods_var_raw('ui_reorder_field', $this->pod_data['options']); if (in_array('reorder', $actions_enabled) && !in_array('reorder', $actions_disabled) && !empty($reorder_field) && (!empty($this->pod_data['object_fields']) && isset($this->pod_data['object_fields'][$reorder_field]) || isset($this->pod_data['fields'][$reorder_field]))) { $ui['reorder'] = array('on' => $reorder_field); $ui['orderby'] = $reorder_field; $ui['orderby_dir'] = 'ASC'; } if (!empty($author_restrict)) { $ui['restrict'] = array('author_restrict' => $author_restrict); } if (!in_array('delete', $ui['actions_disabled'])) { $ui['actions_bulk'] = array('delete' => array('label' => __('Delete', 'pods'))); } $detail_url = pods_var('detail_url', $this->pod_data['options']); if (0 < strlen($detail_url)) { $ui['actions_custom'] = array('view_url' => array('label' => 'View', 'link' => get_site_url() . '/' . $detail_url)); } // @todo Customize the Add New / Manage links to point to their correct menu items $ui = apply_filters('pods_admin_ui_' . $this->pod, apply_filters('pods_admin_ui', $ui, $this->pod, $this), $this->pod, $this); // Override UI options foreach ($options as $option => $value) { $ui[$option] = $value; } $this->ui = $ui; return pods_ui($this); } do_action('pods_admin_ui_custom', $this); do_action('pods_admin_ui_custom_' . $this->pod, $this); }
/** * Add Admin Bar links */ public function admin_bar_links() { global $wp_admin_bar, $pods; if (!is_user_logged_in() || !is_admin_bar_showing()) { return; } $all_pods = pods_api()->load_pods(array('type' => 'pod', 'fields' => false)); // Add New item links for all pods foreach ($all_pods as $pod) { if (0 == $pod['options']['show_in_menu']) { continue; } if (!pods_is_admin(array('pods', 'pods_content', 'pods_add_' . $pod['name']))) { continue; } $singular_label = pods_var_raw('label_singular', $pod['options'], pods_var_raw('label', $pod, ucwords(str_replace('_', ' ', $pod['name'])), null, true), null, true); $wp_admin_bar->add_node(array('id' => 'new-pod-' . $pod['name'], 'title' => $singular_label, 'parent' => 'new-content', 'href' => admin_url('admin.php?page=pods-manage-' . $pod['name'] . '&action=add'))); } // Add edit link if we're on a pods page if (is_object($pods) && !is_wp_error($pods) && !empty($pods->id) && isset($pods->pod_data) && !empty($pods->pod_data) && 'pod' == $pods->pod_data['type']) { $pod = $pods->pod_data; if (pods_is_admin(array('pods', 'pods_content', 'pods_edit_' . $pod['name']))) { $singular_label = pods_var_raw('label_singular', $pod['options'], pods_var_raw('label', $pod, ucwords(str_replace('_', ' ', $pod['name'])), null, true), null, true); $wp_admin_bar->add_node(array('title' => sprintf(__('Edit %s', 'pods'), $singular_label), 'id' => 'edit-pod', 'href' => admin_url('admin.php?page=pods-manage-' . $pod['name'] . '&action=edit&id=' . $pods->id()))); } } }
<?php if (pods_is_admin(array('pods')) && !in_array('delete', $obj->actions_disabled) && !in_array('delete', $obj->actions_hidden)) { ?> <div id="delete-action"> <a class="submitdelete deletion" href="<?php echo pods_query_arg(array('action' => 'delete')); ?> " onclick="return confirm('You are about to permanently delete this item\n Choose \'Cancel\' to stop, \'OK\' to delete.');"><?php _e('Delete', 'pods'); ?> </a> </div> <!-- /#delete-action --> <?php } if (pods_is_admin(array('pods')) && !in_array('process_job', $obj->actions_disabled) && !in_array('process_job', $obj->actions_hidden) && 'queued' == $item['status']) { ?> <div id="preview-action"> <a class="preview button" href="<?php echo pods_query_arg(array('action' => 'process_job')); ?> "><?php _e('Process Job', 'pods-jobs-queue'); ?> </a> </div> <!-- /#delete-action --> <?php } ?>
<?php } ?> </div> <?php } ?> </div> <!-- /#minor-publishing --> <?php } ?> <div id="major-publishing-actions"> <?php if (pods_is_admin(array('pods', 'pods_delete_' . $pod->pod)) && !in_array('delete', $obj->actions_disabled) && !in_array('delete', $obj->actions_hidden)) { ?> <div id="delete-action"> <a class="submitdelete deletion" href="<?php echo pods_query_arg(array('action' => 'delete')); ?> " onclick="return confirm('You are about to permanently delete this item\n Choose \'Cancel\' to stop, \'OK\' to delete.');"><?php _e('Delete', 'pods'); ?> </a> </div> <!-- /#delete-action --> <?php } ?>
public function restricted($action = 'edit', $row = null) { $restricted = false; $restrict = array(); if (isset($this->restrict[$action])) { $restrict = (array) $this->restrict[$action]; } $author_restrict = false; if (!empty($this->restrict['author_restrict']) && $restrict == $this->restrict['author_restrict']) { $author_restrict = true; if (is_object($this->pod)) { $restricted = true; if (pods_is_admin(array('pods', 'pods_content'))) { $restricted = false; } elseif ('manage' == $action) { if (!in_array('edit', $this->actions_disabled) && current_user_can('pods_edit_' . $this->pod->pod) && current_user_can('pods_edit_others_' . $this->pod->pod)) { $restricted = false; } elseif (!in_array('delete', $this->actions_disabled) && current_user_can('pods_delete_' . $this->pod->pod) && current_user_can('pods_delete_others_' . $this->pod->pod)) { $restricted = false; } elseif (current_user_can('pods_' . $action . '_' . $this->pod->pod) && current_user_can('pods_' . $action . '_others_' . $this->pod->pod)) { $restricted = false; } } elseif (current_user_can('pods_' . $action . '_' . $this->pod->pod) && current_user_can('pods_' . $action . '_others_' . $this->pod->pod)) { $restricted = false; } } /* @todo determine proper logic for non-pods capabilities else { $restricted = true; if ( pods_is_admin( array( 'pods', 'pods_content' ) ) ) $restricted = false; elseif ( current_user_can( 'pods_' . $action . '_others_' . $_tbd ) ) $restricted = false; }*/ } if ($restricted && !empty($restrict)) { $relation = strtoupper(trim(pods_var('relation', $restrict, 'AND', null, true))); if ('AND' != $relation) { $relation = 'OR'; } $okay = true; foreach ($restrict as $field => $match) { if ('relation' == $field) { continue; } if (is_array($match)) { $match_okay = true; $match_relation = strtoupper(trim(pods_var('relation', $match, 'OR', null, true))); if ('AND' != $match_relation) { $match_relation = 'OR'; } foreach ($match as $the_field => $the_match) { if ('relation' == $the_field) { continue; } $value = null; if (is_object($this->pod)) { $value = $this->pod->field($the_match, true); } else { if (empty($row)) { $row = $this->row; } if (isset($row[$the_match])) { if (is_array($row[$the_match])) { if (false !== strpos($the_match, '.')) { $the_matches = explode('.', $the_match); $value = $row[$the_match]; foreach ($the_matches as $m) { if (is_array($value) && isset($value[$m])) { $value = $value[$m]; } else { $value = null; break; } } } } else { $value = $row[$the_match]; } } } if (is_array($value)) { if (!in_array($the_match, $value)) { $match_okay = false; } elseif ('OR' == $match_relation) { $match_okay = true; break; } } elseif ($value == $the_match) { $match_okay = false; } elseif ('OR' == $match_relation) { $match_okay = true; break; } } if (!$match_okay) { $okay = false; } if ('OR' == $relation) { $okay = true; break; } } else { $value = null; if (is_object($this->pod)) { $value = $this->pod->field($match, true); } else { if (empty($row)) { $row = $this->row; } if (isset($row[$match])) { if (is_array($row[$match])) { if (false !== strpos($match, '.')) { $matches = explode('.', $match); $value = $row[$match]; foreach ($matches as $m) { if (is_array($value) && isset($value[$m])) { $value = $value[$m]; } else { $value = null; break; } } } } else { $value = $row[$match]; } } } if (is_array($value)) { if (!in_array($match, $value)) { $okay = false; } elseif ('OR' == $relation) { $okay = true; break; } } elseif ($value != $match) { $okay = false; } elseif ('OR' == $relation) { $okay = true; break; } } } if (!empty($author_restrict)) { if (is_object($this->pod) && 'manage' == $action) { if (!in_array('edit', $this->actions_disabled) && !current_user_can('pods_edit_' . $this->pod->pod) && !in_array('delete', $this->actions_disabled) && !current_user_can('pods_delete_' . $this->pod->pod)) { $okay = false; } } if (is_object($this->pod) && !current_user_can('pods_' . $action . '_' . $this->pod->pod)) { $okay = false; } /* @todo determine proper logic for non-pods capabilities elseif ( !current_user_can( 'pods_' . $action . '_' . $_tbd ) ) $okay = false;*/ if (!$okay && !empty($row)) { foreach ($this->restrict['author_restrict'] as $key => $val) { $author_restricted = $this->get_field($key); if (!empty($author_restricted)) { if (!is_array($author_restricted)) { $author_restricted = (array) $author_restricted; } if (is_array($val)) { foreach ($val as $v) { if (in_array($v, $author_restricted)) { $okay = true; } } } elseif (in_array($val, $author_restricted)) { $okay = true; } } } } } if ($okay) { $restricted = false; } } $restricted = $this->do_hook('restricted_' . $action, $restricted, $restrict, $action, $row); return $restricted; }
function admin_delete($id, $obj) { global $wp_roles; $id = $obj->id; if (!isset($obj->data[$id])) { return $obj->error(__('Role not found, it cannot be deleted.', 'pods')); } $default_role = get_option('default_role'); if ($id == $default_role) { return $obj->error(sprintf(__('You cannot remove the <strong>%s</strong> role, you must set a new default role for the site first.', 'pods'), $obj->data[$id]['name'])); } $wp_user_search = new WP_User_Search('', '', $id); $users = $wp_user_search->get_results(); if (!empty($users) && is_array($users)) { foreach ($users as $user) { $user_object = new WP_User($user); if ($user_object->has_cap($id)) { $user_object->remove_role($id); $user_object->set_role($default_role); } } } remove_role($id); $roles = array(); foreach ($wp_roles->role_objects as $key => $role) { $count = $this->count_users($key); $roles[$key] = array('id' => $key, 'label' => $wp_roles->role_names[$key], 'name' => $key, 'capabilities' => count((array) $role->capabilities), 'users' => sprintf(_n('%s User', '%s Users', $count, 'pods'), $count)); if ($default_role == $key) { $roles[$key]['label'] .= ' (site default)'; } if (0 < $count && pods_is_admin(array('list_users'))) { $roles[$key]['users'] .= '<br /><a href="' . admin_url(esc_url('users.php?role=' . $key)) . '">' . __('View Users', 'pods') . '</a>'; } } $name = $obj->data[$id]['label'] . ' (' . $obj->data[$id]['name'] . ')'; $obj->data = $roles; $obj->total = count($roles); $obj->total_found = count($roles); $obj->message('<strong>' . $name . '</strong> ' . __('role removed from site.', 'pods')); }
/** * Handle the Admin AJAX request to process the queue */ public static function admin_ajax_process_queue() { include_once 'Pods_Jobs_Queue_API.php'; // Check if request uses API key, and if incorrect, don't serve request if (isset($_REQUEST['pods_jobs_queue_api_key'])) { if (!defined('PODS_JOBS_QUEUE_API_KEY') || PODS_JOBS_QUEUE_API_KEY != $_REQUEST['pods_jobs_queue_api_key']) { die; } } elseif (!is_user_logged_in() || !pods_is_admin('pods', 'pods_jobs_queue')) { die; } Pods_Jobs_Queue_API::run_queue(); // AJAX must die die; }