/** * Primary method for downloading and processing email replies */ public function download_and_process_email_replies($connection_details) { imap_timeout(IMAP_OPENTIMEOUT, apply_filters('supportflow_imap_open_timeout', 5)); $ssl = $connection_details['imap_ssl'] ? '/ssl' : ''; $ssl = apply_filters('supportflow_imap_ssl', $ssl, $connection_details['imap_host']); $mailbox = "{{$connection_details['imap_host']}:{$connection_details['imap_port']}{$ssl}}"; $inbox = "{$mailbox}{$connection_details['inbox']}"; $archive_box = "{$mailbox}{$connection_details['archive']}"; $imap_connection = imap_open($mailbox, $connection_details['username'], $connection_details['password']); $redacted_connection_details = $connection_details; $redacted_connection_details['password'] = '******'; // redact the password to avoid unnecessarily exposing it in logs $imap_errors = imap_errors(); SupportFlow()->extend->logger->log('email_retrieve', __METHOD__, $imap_connection ? __('Successfully opened IMAP connection.', 'supportflow') : __('Failed to open IMAP connection.', 'supportflow'), compact('redacted_connection_details', 'mailbox', 'imap_errors')); if (!$imap_connection) { return new WP_Error('connection-error', __('Error connecting to mailbox', 'supportflow')); } // Check to see if the archive mailbox exists, and create it if it doesn't $mailboxes = imap_getmailboxes($imap_connection, $mailbox, '*'); if (!wp_filter_object_list($mailboxes, array('name' => $archive_box))) { imap_createmailbox($imap_connection, $archive_box); } // Make sure here are new emails to process $email_count = imap_num_msg($imap_connection); if ($email_count < 1) { SupportFlow()->extend->logger->log('email_retrieve', __METHOD__, __('No new messages to process.', 'supportflow'), compact('mailboxes')); return false; } $emails = imap_search($imap_connection, 'ALL', SE_UID); $email_count = min($email_count, apply_filters('supportflow_max_email_process_count', 20)); $emails = array_slice($emails, 0, $email_count); $processed = 0; // Process each new email and put it in the archive mailbox when done. foreach ($emails as $uid) { $email = new stdClass(); $email->uid = $uid; $email->msgno = imap_msgno($imap_connection, $email->uid); $email->headers = imap_headerinfo($imap_connection, $email->msgno); $email->structure = imap_fetchstructure($imap_connection, $email->msgno); $email->body = $this->get_body_from_connection($imap_connection, $email->msgno); if (0 === strcasecmp($connection_details['username'], $email->headers->from[0]->mailbox . '@' . $email->headers->from[0]->host)) { $connection_details['password'] = '******'; // redact the password to avoid unnecessarily exposing it in logs SupportFlow()->extend->logger->log('email_retrieve', __METHOD__, __('Skipping message because it was sent from a SupportFlow account.', 'supportflow'), compact('email')); continue; } // @todo Confirm this a message we want to process $result = $this->process_email($imap_connection, $email, $email->msgno, $connection_details['username'], $connection_details['account_id']); // If it was successful, move the email to the archive if ($result) { imap_mail_move($imap_connection, $email->uid, $connection_details['archive'], CP_UID); $processed++; } } imap_close($imap_connection, CL_EXPUNGE); $status_message = sprintf(__('Processed %d emails', 'supportflow'), $processed); SupportFlow()->extend->logger->log('email_retrieve', __METHOD__, $status_message); return $status_message; }
function submenu_get_children_ids($id, $items) { $ids = wp_filter_object_list($items, array('menu_item_parent' => $id), 'and', 'ID'); foreach ($ids as $id) { $ids = array_merge($ids, submenu_get_children_ids($id, $items)); } return $ids; }
/** * Return translated context labels * * @return array Context label translations */ public function get_context_labels() { global $wp_post_types; $post_types = wp_filter_object_list($wp_post_types, array(), null, 'label'); $post_types = array_diff_key($post_types, array_flip($this->get_excluded_post_types())); add_action('registered_post_type', array($this, '_registered_post_type'), 10, 2); return $post_types; }
/** * Whether the current page has any tools. * * @return bool */ function has_tool() { $all_rules = dp_addthis_get_rules(); $rule_contexts = array_unique(wp_filter_object_list($all_rules, '', 'and', 'context')); $current_contexts = dp_addthis_get_contexts(); $has_contexts = array_intersect($rule_contexts, $current_contexts); return !empty($has_contexts); }
public static function get_context_labels() { global $wp_post_types; $post_types = wp_filter_object_list($wp_post_types, array(), null, 'label'); $post_types = array_diff_key($post_types, array_flip(self::get_ignored_post_types())); add_action('registered_post_type', array(__CLASS__, '_registered_post_type'), 10, 2); return $post_types; }
/** * Return an array of the post types that calendars are available on * * You can filter this to enable a post calendar for just about any kind of * post type with an interface. * * @since 0.1.0 * * @return array */ function wp_event_calendar_allowed_post_types() { global $_wp_post_type_features; // Get which post types support events $supports = wp_filter_object_list($_wp_post_type_features, array('events' => true)); $types = array_keys($supports); // Filter & return return apply_filters('wp_event_calendar_allowed_post_types', $types, $supports); }
/** * Get all children */ function get_children($parent, $items) { $children = wp_filter_object_list($items, array('menu_item_parent' => $parent->ID)); if (0 === count($children)) { return array(); } foreach ($children as $child) { $children = array_merge($children, $this->get_children($child, $items)); } return $children; }
private function findActiveDepth($childItem, $parentItem, $allItems) { $depth = 0; while ($childItem->menu_item_parent) { $depth++; if ($childItem->menu_item_parent == $parentItem->ID) { return $depth; } $childItems = wp_filter_object_list($allItems, array('ID' => $childItem->menu_item_parent)); $childItem = array_pop($childItems); } }
/** * @ticket 27113 */ function test_orphan_nav_menu_item() { // Create an orphan nav menu item $custom_item_id = wp_update_nav_menu_item(0, 0, array('menu-item-type' => 'custom', 'menu-item-title' => 'Wordpress.org', 'menu-item-link' => 'http://wordpress.org', 'menu-item-status' => 'publish')); // Confirm it saved properly $custom_item = wp_setup_nav_menu_item(get_post($custom_item_id)); $this->assertEquals('Wordpress.org', $custom_item->title); // Update the orphan with an associated nav menu wp_update_nav_menu_item($this->menu_id, $custom_item_id, array('menu-item-title' => 'WordPress.org')); $menu_items = wp_get_nav_menu_items($this->menu_id); $custom_item = wp_filter_object_list($menu_items, array('db_id' => $custom_item_id)); $custom_item = array_pop($custom_item); $this->assertEquals('WordPress.org', $custom_item->title); }
/** * Retrieve a list of registered modules. * * @since 1.1 * @return array */ public static function get(array $args = null, $operator = 'AND') { if (empty($args)) { return self::$modules; } $filtered = array(); $count = count($args); foreach (self::$modules as $key => $obj) { $matched = 0; foreach ($args as $m_key => $m_value) { if (property_exists($obj, $m_key)) { $obj_prop = $obj[$m_key]; if (is_array($obj_prop) && is_array($m_value)) { $m_akey = wp_filter_object_list(array($obj_prop), $m_value, $operator); if (!empty($m_akey)) { $matched++; } } elseif ($obj_prop == $m_value) { $matched++; } } } $b = false; switch (strtoupper($operator)) { default: case 'AND': $b = $matched == $count; break; case 'OR': $b = $matched > 0; break; case 'NOT': $b = $matched == 0; break; } if ($b) { $filtered[$key] = $obj; } } return $filtered; }
public function filter_menu_items($menu_items, $form_id, $compact) { $form_meta = GFFormsModel::get_form_meta($form_id); $results_fields = $this->get_fields($form_meta); if (false === empty($results_fields)) { $form_id = $form_meta["id"]; $link_class = ""; if (rgget("page") == "gf_new_form") { $link_class = "gf_toolbar_disabled"; } else { if (rgget("page") == "gf_entries" && rgget("view") == "gf_results_" . $this->_slug) { $link_class = "gf_toolbar_active"; } } $sub_menu_items = array(); $sub_menu_items[] = array('label' => $this->_title, 'title' => __("View results generated by this form", "gravityforms"), 'link_class' => $link_class, 'url' => admin_url("admin.php?page=gf_entries&view=gf_results_{$this->_slug}&id={$form_id}"), 'capabilities' => $this->_capabilities); $duplicate_submenus = wp_filter_object_list(rgars($menu_items, "results/sub_menu_items"), array("label" => $sub_menu_items[0]["label"])); if (count($duplicate_submenus) > 0) { return $menu_items; } // If there's already a menu item with the key "results" then merge the two. if (isset($menu_items["results"])) { $existing_link_class = $menu_items["results"]["link_class"]; $link_class == empty($existing_link_class) ? $link_class : $existing_link_class; $existing_capabilities = $menu_items["results"]["capabilities"]; $merged_capabilities = array_merge($existing_capabilities, $this->_capabilities); $existing_sub_menu_items = $menu_items["results"]["sub_menu_items"]; $merged_sub_menu_items = array_merge($existing_sub_menu_items, $sub_menu_items); $menu_items["results"]["link_class"] = $link_class; $menu_items["results"]["capabilities"] = $merged_capabilities; $menu_items["results"]["sub_menu_items"] = $merged_sub_menu_items; $menu_items["results"]["label"] = __("Results", "gravityforms"); } else { // so far during the page cycle this is the only menu item for this key $menu_items["results"] = array('label' => $compact ? __("Results", "gravityforms") : $this->_title, 'title' => __("View results generated by this form", "gravityforms"), 'url' => "", 'onclick' => "return false;", 'menu_class' => 'gf_form_toolbar_results', 'link_class' => $link_class, 'capabilities' => $this->_capabilities, 'sub_menu_items' => $sub_menu_items, 'priority' => 750); } } return $menu_items; }
public function get_columns() { $posts_columns = array(); $posts_columns['cb'] = '<input type="checkbox" />'; $posts_columns['icon'] = ''; /* translators: column name */ $posts_columns['title'] = _x('File', 'column name'); $posts_columns['author'] = __('Author'); $taxonomies = get_taxonomies_for_attachments('objects'); $taxonomies = wp_filter_object_list($taxonomies, array('show_admin_column' => true), 'and', 'name'); /** * Filter the taxonomy columns for attachments in the Media list table. * * @since 3.5.0 * * @param array $taxonomies An array of registered taxonomies to show for attachments. * @param string $post_type The post type. Default 'attachment'. */ $taxonomies = apply_filters('manage_taxonomies_for_attachment_columns', $taxonomies, 'attachment'); $taxonomies = array_filter($taxonomies, 'taxonomy_exists'); foreach ($taxonomies as $taxonomy) { if ('category' == $taxonomy) { $column_key = 'categories'; } elseif ('post_tag' == $taxonomy) { $column_key = 'tags'; } else { $column_key = 'taxonomy-' . $taxonomy; } $posts_columns[$column_key] = get_taxonomy($taxonomy)->labels->name; } /* translators: column name */ if (!$this->detached) { $posts_columns['parent'] = _x('Uploaded to', 'column name'); if (post_type_supports('attachment', 'comments')) { $posts_columns['comments'] = '<span class="vers"><span title="' . esc_attr__('Comments') . '" class="comment-grey-bubble"></span></span>'; } } /* translators: column name */ $posts_columns['date'] = _x('Date', 'column name'); /** * Filter the Media list table columns. * * @since 2.5.0 * * @param array $posts_columns An array of columns displayed in the Media list table. * @param bool $detached Whether the list table contains media not attached * to any posts. Default true. */ $posts_columns = apply_filters('manage_media_columns', $posts_columns, $this->detached); return $posts_columns; }
public static function update_confirmation($form, $lead = null, $event = '') { if (!is_array(rgar($form, 'confirmations'))) { return $form; } if (!empty($event)) { $confirmations = wp_filter_object_list($form['confirmations'], array('event' => $event)); } else { $confirmations = $form['confirmations']; } // if there is only one confirmation, don't bother with the conditional logic, just return it // this is here mostly to avoid the semi-costly GFFormsModel::create_lead() function unless we really need it if (is_array($form['confirmations']) && count($confirmations) <= 1) { $form['confirmation'] = reset($confirmations); return $form; } if (empty($lead)) { $lead = GFFormsModel::create_lead($form); } foreach ($confirmations as $confirmation) { if (rgar($confirmation, 'event') != $event) { continue; } if (rgar($confirmation, 'isDefault')) { continue; } if (isset($confirmation['isActive']) && !$confirmation['isActive']) { continue; } $logic = rgar($confirmation, 'conditionalLogic'); if (GFCommon::evaluate_conditional_logic($logic, $form, $lead)) { $form['confirmation'] = $confirmation; return $form; } } $filtered_list = wp_filter_object_list($form['confirmations'], array('isDefault' => true)); $form['confirmation'] = reset($filtered_list); return $form; }
/** * The main topic loop. WordPress makes this easy for us * * @since 2.0.0 bbPress (r2485) * * @param array $args All the arguments supported by {@link WP_Query} * @uses current_user_can() To check if the current user can edit other's topics * @uses bbp_get_topic_post_type() To get the topic post type * @uses WP_Query To make query and get the topics * @uses is_page() To check if it's a page * @uses bbp_is_single_forum() To check if it's a forum * @uses bbp_get_forum_id() To get the forum id * @uses bbp_get_paged() To get the current page value * @uses bbp_get_super_stickies() To get the super stickies * @uses bbp_get_stickies() To get the forum stickies * @uses bbp_use_pretty_urls() To check if the site is using pretty URLs * @uses get_permalink() To get the permalink * @uses add_query_arg() To add custom args to the url * @uses apply_filters() Calls 'bbp_topics_pagination' with the pagination args * @uses paginate_links() To paginate the links * @uses apply_filters() Calls 'bbp_has_topics' with * bbPres::topic_query::have_posts() * and bbPres::topic_query * @return object Multidimensional array of topic information */ function bbp_has_topics($args = array()) { /** Defaults **************************************************************/ // Other defaults $default_topic_search = !empty($_REQUEST['ts']) ? $_REQUEST['ts'] : false; $default_show_stickies = (bool) (bbp_is_single_forum() || bbp_is_topic_archive()) && false === $default_topic_search; $default_post_parent = bbp_is_single_forum() ? bbp_get_forum_id() : 'any'; // Default argument array $default = array('post_type' => bbp_get_topic_post_type(), 'post_parent' => $default_post_parent, 'meta_key' => '_bbp_last_active_time', 'meta_type' => 'DATETIME', 'orderby' => 'meta_value', 'order' => 'DESC', 'posts_per_page' => bbp_get_topics_per_page(), 'paged' => bbp_get_paged(), 'show_stickies' => $default_show_stickies, 'max_num_pages' => false); // Only add 's' arg if searching for topics // See https://bbpress.trac.wordpress.org/ticket/2607 if (!empty($default_topic_search)) { $default['s'] = $default_topic_search; } // What are the default allowed statuses (based on user caps) if (bbp_get_view_all()) { // Default view=all statuses $post_statuses = array(bbp_get_public_status_id(), bbp_get_closed_status_id(), bbp_get_spam_status_id(), bbp_get_trash_status_id(), bbp_get_pending_status_id()); // Add support for private status if (current_user_can('read_private_topics')) { $post_statuses[] = bbp_get_private_status_id(); } // Join post statuses together $default['post_status'] = implode(',', $post_statuses); // Lean on the 'perm' query var value of 'readable' to provide statuses } else { $default['perm'] = 'readable'; } // Maybe query for topic tags if (bbp_is_topic_tag()) { $default['term'] = bbp_get_topic_tag_slug(); $default['taxonomy'] = bbp_get_topic_tag_tax_id(); } /** Setup *****************************************************************/ // Parse arguments against default values $r = bbp_parse_args($args, $default, 'has_topics'); // Get bbPress $bbp = bbpress(); // Call the query $bbp->topic_query = new WP_Query($r); // Set post_parent back to 0 if originally set to 'any' if ('any' === $r['post_parent']) { $r['post_parent'] = 0; } // Limited the number of pages shown if (!empty($r['max_num_pages'])) { $bbp->topic_query->max_num_pages = $r['max_num_pages']; } /** Stickies **************************************************************/ // Put sticky posts at the top of the posts array if (!empty($r['show_stickies']) && $r['paged'] <= 1) { // Get super stickies and stickies in this forum $stickies = bbp_get_super_stickies(); // Get stickies for current forum if (!empty($r['post_parent'])) { $stickies = array_merge($stickies, bbp_get_stickies($r['post_parent'])); } // Remove any duplicate stickies $stickies = array_unique($stickies); // We have stickies if (is_array($stickies) && !empty($stickies)) { // Start the offset at -1 so first sticky is at correct 0 offset $sticky_offset = -1; // Loop over topics and relocate stickies to the front. foreach ($stickies as $sticky_index => $sticky_ID) { // Get the post offset from the posts array $post_offsets = wp_filter_object_list($bbp->topic_query->posts, array('ID' => $sticky_ID), 'OR', 'ID'); // Continue if no post offsets if (empty($post_offsets)) { continue; } // Loop over posts in current query and splice them into position foreach (array_keys($post_offsets) as $post_offset) { $sticky_offset++; $sticky = $bbp->topic_query->posts[$post_offset]; // Remove sticky from current position array_splice($bbp->topic_query->posts, $post_offset, 1); // Move to front, after other stickies array_splice($bbp->topic_query->posts, $sticky_offset, 0, array($sticky)); // Cleanup unset($stickies[$sticky_index]); unset($sticky); } // Cleanup unset($post_offsets); } // Cleanup unset($sticky_offset); // If any posts have been excluded specifically, Ignore those that are sticky. if (!empty($stickies) && !empty($r['post__not_in'])) { $stickies = array_diff($stickies, $r['post__not_in']); } // Fetch sticky posts that weren't in the query results if (!empty($stickies)) { // Query to use in get_posts to get sticky posts $sticky_query = array('post_type' => bbp_get_topic_post_type(), 'post_parent' => 'any', 'meta_key' => '_bbp_last_active_time', 'meta_type' => 'DATETIME', 'orderby' => 'meta_value', 'order' => 'DESC', 'include' => $stickies); // Cleanup unset($stickies); // Conditionally exclude private/hidden forum ID's $exclude_forum_ids = bbp_exclude_forum_ids('array'); if (!empty($exclude_forum_ids)) { $sticky_query['post_parent__not_in'] = $exclude_forum_ids; } // What are the default allowed statuses (based on user caps) if (bbp_get_view_all()) { $sticky_query['post_status'] = $r['post_status']; // Lean on the 'perm' query var value of 'readable' to provide statuses } else { $sticky_query['post_status'] = $r['perm']; } // Get all stickies $sticky_posts = get_posts($sticky_query); if (!empty($sticky_posts)) { // Get a count of the visible stickies $sticky_count = count($sticky_posts); // Merge the stickies topics with the query topics . $bbp->topic_query->posts = array_merge($sticky_posts, $bbp->topic_query->posts); // Adjust loop and counts for new sticky positions $bbp->topic_query->found_posts = (int) $bbp->topic_query->found_posts + (int) $sticky_count; $bbp->topic_query->post_count = (int) $bbp->topic_query->post_count + (int) $sticky_count; // Cleanup unset($sticky_posts); } } } } // If no limit to posts per page, set it to the current post_count if (-1 === $r['posts_per_page']) { $r['posts_per_page'] = $bbp->topic_query->post_count; } // Add pagination values to query object $bbp->topic_query->posts_per_page = $r['posts_per_page']; $bbp->topic_query->paged = $r['paged']; // Only add pagination if query returned results if (((int) $bbp->topic_query->post_count || (int) $bbp->topic_query->found_posts) && (int) $bbp->topic_query->posts_per_page) { // Limit the number of topics shown based on maximum allowed pages if (!empty($r['max_num_pages']) && $bbp->topic_query->found_posts > $bbp->topic_query->max_num_pages * $bbp->topic_query->post_count) { $bbp->topic_query->found_posts = $bbp->topic_query->max_num_pages * $bbp->topic_query->post_count; } // If pretty permalinks are enabled, make our pagination pretty if (bbp_use_pretty_urls()) { // User's topics if (bbp_is_single_user_topics()) { $base = bbp_get_user_topics_created_url(bbp_get_displayed_user_id()); // User's favorites } elseif (bbp_is_favorites()) { $base = bbp_get_favorites_permalink(bbp_get_displayed_user_id()); // User's subscriptions } elseif (bbp_is_subscriptions()) { $base = bbp_get_subscriptions_permalink(bbp_get_displayed_user_id()); // Root profile page } elseif (bbp_is_single_user()) { $base = bbp_get_user_profile_url(bbp_get_displayed_user_id()); // View } elseif (bbp_is_single_view()) { $base = bbp_get_view_url(); // Topic tag } elseif (bbp_is_topic_tag()) { $base = bbp_get_topic_tag_link(); // Page or single post } elseif (is_page() || is_single()) { $base = get_permalink(); // Forum archive } elseif (bbp_is_forum_archive()) { $base = bbp_get_forums_url(); // Topic archive } elseif (bbp_is_topic_archive()) { $base = bbp_get_topics_url(); // Default } else { $base = get_permalink((int) $r['post_parent']); } // Use pagination base $base = trailingslashit($base) . user_trailingslashit(bbp_get_paged_slug() . '/%#%/'); // Unpretty pagination } else { $base = add_query_arg('paged', '%#%'); } // Pagination settings with filter $bbp_topic_pagination = apply_filters('bbp_topic_pagination', array('base' => $base, 'format' => '', 'total' => $r['posts_per_page'] === $bbp->topic_query->found_posts ? 1 : ceil((int) $bbp->topic_query->found_posts / (int) $r['posts_per_page']), 'current' => (int) $bbp->topic_query->paged, 'prev_text' => is_rtl() ? '→' : '←', 'next_text' => is_rtl() ? '←' : '→', 'mid_size' => 1)); // Add pagination to query object $bbp->topic_query->pagination_links = paginate_links($bbp_topic_pagination); // Remove first page from pagination $bbp->topic_query->pagination_links = str_replace(bbp_get_paged_slug() . "/1/'", "'", $bbp->topic_query->pagination_links); } // Return object return apply_filters('bbp_has_topics', $bbp->topic_query->have_posts(), $bbp->topic_query); }
/** * Output HTML for the settings page * Called from add_options_page */ function settings_page_output() { $arr_settings_tabs = $this->getSettingsTabs(); ?> <div class="wrap"> <h1 class="SimpleHistoryPageHeadline"> <div class="dashicons dashicons-backup SimpleHistoryPageHeadline__icon"></div> <?php _e("Simple History Settings", "simple-history"); ?> </h1> <?php $active_tab = isset($_GET["selected-tab"]) ? $_GET["selected-tab"] : "settings"; $settings_base_url = menu_page_url(SimpleHistory::SETTINGS_MENU_SLUG, 0); ?> <h2 class="nav-tab-wrapper"> <?php foreach ($arr_settings_tabs as $one_tab) { $tab_slug = $one_tab["slug"]; printf('<a href="%3$s" class="nav-tab %4$s">%1$s</a>', $one_tab["name"], $tab_slug, esc_url(add_query_arg("selected-tab", $tab_slug, $settings_base_url)), $active_tab == $tab_slug ? "nav-tab-active" : ""); } ?> </h2> <?php // Output contents for selected tab $arr_active_tab = wp_filter_object_list($arr_settings_tabs, array("slug" => $active_tab)); $arr_active_tab = current($arr_active_tab); // We must have found an active tab and it must have a callable function if (!$arr_active_tab || !is_callable($arr_active_tab["function"])) { wp_die(__("No valid callback found", "simple-history")); } $args = array("arr_active_tab" => $arr_active_tab); call_user_func_array($arr_active_tab["function"], $args); ?> </div> <?php }
/** * Get a widget's instantiated object based on its name * * @param string $id_base Name of the widget * @return WP_Widget|false */ private function get_widget_obj($id_base) { global $wp_widget_factory; $widget = wp_filter_object_list($wp_widget_factory->widgets, array('id_base' => $id_base)); if (empty($widget)) { false; } return array_pop($widget); }
/** * Get a list of post types that support a specific named feature. * * @param string $feature * * @return array */ static function get_post_types_supporting($feature) { global $_wp_post_type_features; $post_types = array_keys(wp_filter_object_list($_wp_post_type_features, array($feature => true))); return $post_types; }
public function get_recommended_plugins($site_type) { $plugins = $this->get_plugins($site_type); if (!$plugins) { return false; } return wp_filter_object_list((array) $plugins, array('installation' => 'recommended')); }
function _postExpiratorTaxonomy($opts) { if (empty($opts)) { return false; } extract($opts); if (!isset($name)) { return false; } if (!isset($id)) { $id = $name; } if (!isset($disabled)) { $disabled = false; } if (!isset($onchange)) { $onchange = ''; } if (!isset($type)) { $type = ''; } $taxonomies = get_object_taxonomies($type, 'object'); $taxonomies = wp_filter_object_list($taxonomies, array('hierarchical' => true)); if (empty($taxonomies)) { $disabled = true; } $rv = array(); $rv[] = '<select name="' . $name . '" id="' . $id . '"' . ($disabled == true ? ' disabled="disabled"' : '') . ' onchange="' . $onchange . '">'; foreach ($taxonomies as $taxonomy) { $rv[] = '<option value="' . $taxonomy->name . '" ' . ($selected == $taxonomy->name ? 'selected="selected"' : '') . '>' . $taxonomy->name . '</option>'; } $rv[] = '</select>'; return implode("<br/>/n", $rv); }
public function get_first_map(&$blocks) { $unserialized_blocks = array_map('maybe_unserialize', wp_list_pluck($blocks, 0)); $maps = wp_filter_object_list($unserialized_blocks, array('id_base' => 'cr_gmap_block')); if (!empty($maps)) { $map = array_shift($maps); $index = array_search($map, $unserialized_blocks); unset($blocks[$index]); return $map; } return null; }
/** * Get a list of all registered member type objects. * * @since 2.2.0 * * @see bp_register_member_type() for accepted arguments. * * @param array|string $args Optional. An array of key => value arguments to match against * the member type objects. Default empty array. * @param string $output Optional. The type of output to return. Accepts 'names' * or 'objects'. Default 'names'. * @param string $operator Optional. The logical operation to perform. 'or' means only one * element from the array needs to match; 'and' means all elements * must match. Accepts 'or' or 'and'. Default 'and'. * @return array A list of member type names or objects. */ function bp_get_member_types($args = array(), $output = 'names', $operator = 'and') { $types = buddypress()->members->types; $types = wp_filter_object_list($types, $args, $operator); /** * Filters the array of member type objects. * * This filter is run before the $output filter has been applied, so that * filtering functions have access to the entire member type objects. * * @since 2.2.0 * * @param array $types Member type objects, keyed by name. * @param array $args Array of key=>value arguments for filtering. * @param string $operator 'or' to match any of $args, 'and' to require all. */ $types = apply_filters('bp_get_member_types', $types, $args, $operator); if ('names' === $output) { $types = wp_list_pluck($types, 'name'); } return $types; }
/** * Display hidden information we need for inline editing */ function column_id($item) { global $ad_code_manager; $output = '<div id="inline_' . $item['post_id'] . '" style="display:none;">'; $output .= '<div class="id">' . $item['post_id'] . '</div>'; // Build the fields for the conditionals $output .= '<div class="acm-conditional-fields"><div class="form-new-row">'; $output .= '<h4 class="acm-section-label">' . __('Conditionals', 'ad-code-manager') . '</h4>'; if (!empty($item['conditionals'])) { foreach ($item['conditionals'] as $conditional) { $function = $conditional['function']; $arguments = $conditional['arguments']; $output .= '<div class="conditional-single-field"><div class="conditional-function">'; $output .= '<select name="acm-conditionals[]">'; $output .= '<option value="">' . __('Select conditional', 'ad-code-manager') . '</option>'; foreach ($ad_code_manager->whitelisted_conditionals as $key) { $output .= '<option value="' . esc_attr($key) . '" ' . selected($function, $key, false) . '>'; $output .= esc_html(ucfirst(str_replace('_', ' ', $key))); $output .= '</option>'; } $output .= '</select>'; $output .= '</div><div class="conditional-arguments">'; $output .= '<input name="acm-arguments[]" type="text" value="' . esc_attr(implode(';', $arguments)) . '" size="20" />'; $output .= '<a href="#" class="acm-remove-conditional">Remove</a></div></div>'; } } $output .= '</div><div class="form-field form-add-more"><a href="#" class="button button-secondary add-more-conditionals">' . __('Add more', 'ad-code-manager') . '</a></div>'; $output .= '</div>'; // Build the fields for the normal columns $output .= '<div class="acm-column-fields">'; $output .= '<h4 class="acm-section-label">' . __('URL Variables', 'ad-code-manager') . '</h4>'; foreach ((array) $item['url_vars'] as $slug => $value) { $output .= '<div class="acm-section-single-field">'; $column_id = 'acm-column[' . $slug . ']'; $output .= '<label for="' . esc_attr($column_id) . '">' . esc_html($slug) . '</label>'; // Support for select dropdowns $ad_code_args = wp_filter_object_list($ad_code_manager->current_provider->ad_code_args, array('key' => $slug)); $ad_code_arg = array_shift($ad_code_args); if (isset($ad_code_arg['type']) && 'select' == $ad_code_arg['type']) { $output .= '<select name="' . esc_attr($column_id) . '">'; foreach ($ad_code_arg['options'] as $key => $label) { $output .= '<option value="' . esc_attr($key) . '" ' . selected($value, $key, false) . '>' . esc_attr($label) . '</option>'; } $output .= '</select>'; } else { $output .= '<input name="' . esc_attr($column_id) . '" id="' . esc_attr($column_id) . '" type="text" value="' . esc_attr($value) . '" size="20" aria-required="true">'; } $output .= '</div>'; } $output .= '</div>'; // Build the field for the priority $output .= '<div class="acm-priority-field">'; $output .= '<h4 class="acm-section-label">' . __('Priority', 'ad-code-manager') . '</h4>'; $output .= '<input type="text" name="priority" value="' . esc_attr($item['priority']) . '" />'; $output .= '</div>'; // Build the field for the logical operator $output .= '<div class="acm-operator-field">'; $output .= '<h4 class="acm-section-label">' . __('Logical Operator', 'ad-code-manager') . '</h4>'; $output .= '<select name="operator">'; $operators = array('OR' => __('OR', 'ad-code-manager'), 'AND' => __('AND', 'ad-code-manager')); foreach ($operators as $key => $label) { $output .= '<option ' . selected($item['operator'], $key) . '>' . esc_attr($label) . '</option>'; } $output .= '</select>'; $output .= '</div>'; $output .= '</div>'; return $output; }
/** * Get a list of all registered post type objects. * * @package WordPress * @subpackage Post * @since 2.9.0 * @uses $wp_post_types * @see register_post_type * * @param array|string $args An array of key => value arguments to match against the post type objects. * @param string $output The type of output to return, either post type 'names' or 'objects'. 'names' is the default. * @param string $operator The logical operation to perform. 'or' means only one element * from the array needs to match; 'and' means all elements must match. The default is 'and'. * @return array A list of post type names or objects */ function get_post_types($args = array(), $output = 'names', $operator = 'and') { global $wp_post_types; $field = 'names' == $output ? 'name' : false; return wp_filter_object_list($wp_post_types, $args, $operator, $field); }
function get_columns() { $post_type = $this->screen->post_type; $posts_columns = array(); $posts_columns['cb'] = '<input type="checkbox" />'; /* translators: manage posts column name */ $posts_columns['title'] = _x('Title', 'column name'); if (post_type_supports($post_type, 'author')) { $posts_columns['author'] = __('Author'); } $taxonomies = array(); $taxonomies = get_object_taxonomies($post_type, 'objects'); $taxonomies = wp_filter_object_list($taxonomies, array('show_admin_column' => true), 'and', 'name'); $taxonomies = apply_filters("manage_taxonomies_for_{$post_type}_columns", $taxonomies, $post_type); $taxonomies = array_filter($taxonomies, 'taxonomy_exists'); foreach ($taxonomies as $taxonomy) { if ('category' == $taxonomy) { $column_key = 'categories'; } elseif ('post_tag' == $taxonomy) { $column_key = 'tags'; } else { $column_key = 'taxonomy-' . $taxonomy; } $posts_columns[$column_key] = get_taxonomy($taxonomy)->labels->name; } $post_status = !empty($_REQUEST['post_status']) ? $_REQUEST['post_status'] : 'all'; if (post_type_supports($post_type, 'comments') && !in_array($post_status, array('pending', 'draft', 'future'))) { $posts_columns['comments'] = '<span class="vers"><div title="' . esc_attr__('Comments') . '" class="comment-grey-bubble"></div></span>'; } $posts_columns['date'] = __('Date'); if ('page' == $post_type) { $posts_columns = apply_filters('manage_pages_columns', $posts_columns); } else { $posts_columns = apply_filters('manage_posts_columns', $posts_columns, $post_type); } $posts_columns = apply_filters("manage_{$post_type}_posts_columns", $posts_columns); return $posts_columns; }
/** * Display a list of possible alert types * * @since 0.1.0 */ function wp_user_alerts_methods_picker() { // Query for users $methods = wp_user_alerts_get_alert_methods(); $long = wp_filter_object_list($methods, array('type' => 'long')); $short = wp_filter_object_list($methods, array('type' => 'short')); // Start a buffer ob_start(); // Output methods ?> <h4><?php esc_html_e('Delivery Methods', 'wp-user-alerts'); ?> </h4> <p><?php esc_html_e('Pick from several different communication methods, or leave empty to not alert anyone.', 'wp-user-alerts'); ?> </p> <div id="alert-methods" class="tabs-panel"><?php // User Dashboard if (!empty($long)) { ?> <div><h4><?php esc_html_e('Full Text', 'wp-user-alerts'); ?> </h4><?php wp_user_alert_methods_items($long); ?> </div><?php } // Direct if (!empty($short)) { ?> <div><h4><?php esc_html_e('Short Message (100 characters)', 'wp-user-alerts'); ?> </h4><?php wp_user_alert_methods_items($short); ?> </div><?php } ?> </div><div class="clear"></div><?php // Send the buffer ob_flush(); }
$dates = $wpdb->get_results($sql); #echo '<div class="SimpleHistoryChart__rowsPerDay"></div>'; echo '<div class="SimpleHistoryChart__rowsPerDayGoogleChart"></div>'; // Loop from $period_start_date to $period_end_date $interval = DateInterval::createFromDateString('1 day'); $period = new DatePeriod($period_start_date, $interval, $period_end_date->add(date_interval_create_from_date_string('1 days'))); $str_js_chart_labels = ""; $str_js_chart_data = ""; $str_js_google_chart_data = ""; foreach ($period as $dt) { $datef = _x('M j', "stats: date in rows per day chart", "simple-history"); $str_date = date_i18n($datef, $dt->getTimestamp()); $str_js_chart_labels .= sprintf('"%1$s",', $str_date); // Get data for this day, if exist // Day in object is in format '2014-09-07' $day_data = wp_filter_object_list($dates, array("yearDate" => $dt->format("Y-m-d"))); $day_data_value = 0; if ($day_data) { $day_data_value = (int) current($day_data)->count; } $str_js_chart_data .= sprintf('%1$s,', $day_data_value); $str_js_google_chart_data .= sprintf('["%2$s", %1$d], ', $day_data_value, $str_date); } $str_js_chart_labels = rtrim($str_js_chart_labels, ","); $str_js_chart_data = rtrim($str_js_chart_data, ","); $str_js_google_chart_data = rtrim($str_js_google_chart_data, ","); ?> <script> /**
/** * * @return array */ public function get_columns() { $post_type = $this->screen->post_type; $posts_columns = array(); $posts_columns['cb'] = '<input type="checkbox" />'; /* translators: manage posts column name */ $posts_columns['title'] = _x('Title', 'column name'); if (post_type_supports($post_type, 'author')) { $posts_columns['author'] = __('Author'); } $taxonomies = get_object_taxonomies($post_type, 'objects'); $taxonomies = wp_filter_object_list($taxonomies, array('show_admin_column' => true), 'and', 'name'); /** * Filter the taxonomy columns in the Posts list table. * * The dynamic portion of the hook name, `$post_type`, refers to the post * type slug. * * @since 3.5.0 * * @param array $taxonomies Array of taxonomies to show columns for. * @param string $post_type The post type. */ $taxonomies = apply_filters("manage_taxonomies_for_{$post_type}_columns", $taxonomies, $post_type); $taxonomies = array_filter($taxonomies, 'taxonomy_exists'); foreach ($taxonomies as $taxonomy) { if ('category' == $taxonomy) { $column_key = 'categories'; } elseif ('post_tag' == $taxonomy) { $column_key = 'tags'; } else { $column_key = 'taxonomy-' . $taxonomy; } $posts_columns[$column_key] = get_taxonomy($taxonomy)->labels->name; } $post_status = !empty($_REQUEST['post_status']) ? $_REQUEST['post_status'] : 'all'; if (post_type_supports($post_type, 'comments') && !in_array($post_status, array('pending', 'draft', 'future'))) { $posts_columns['comments'] = '<span class="vers comment-grey-bubble" title="' . esc_attr__('Comments') . '"><span class="screen-reader-text">' . __('Comments') . '</span></span>'; } $posts_columns['date'] = __('Date'); if ('page' == $post_type) { /** * Filter the columns displayed in the Pages list table. * * @since 2.5.0 * * @param array $post_columns An array of column names. */ $posts_columns = apply_filters('manage_pages_columns', $posts_columns); } else { /** * Filter the columns displayed in the Posts list table. * * @since 1.5.0 * * @param array $posts_columns An array of column names. * @param string $post_type The post type slug. */ $posts_columns = apply_filters('manage_posts_columns', $posts_columns, $post_type); } /** * Filter the columns displayed in the Posts list table for a specific post type. * * The dynamic portion of the hook name, `$post_type`, refers to the post type slug. * * @since 3.0.0 * * @param array $post_columns An array of column names. */ return apply_filters("manage_{$post_type}_posts_columns", $posts_columns); }
/** * Filter the page title for BuddyPress pages. * * @since BuddyPress (1.5.0) * * @see wp_title() * @global object $bp BuddyPress global settings. * * @param string $title Original page title. * @param string $sep How to separate the various items within the page title. * @param string $seplocation Direction to display title. * @return string New page title. */ function bp_modify_page_title( $title, $sep = '', $seplocation = '' ) { global $bp; // If this is not a BP page, just return the title produced by WP if ( bp_is_blog_page() ) { return $title; } // If this is a 404, let WordPress handle it if ( is_404() ) { return $title; } // If this is the front page of the site, return WP's title if ( is_front_page() || is_home() ) { return $title; } $title = ''; // Displayed user if ( bp_get_displayed_user_fullname() && ! is_404() ) { // Get the component's ID to try and get its name $component_id = $component_name = bp_current_component(); // Use the component nav name if ( ! empty( $bp->bp_nav[$component_id] ) ) { // Remove counts that are added by the nav item $span = strpos( $bp->bp_nav[ $component_id ]['name'], '<span' ); if ( false !== $span ) { $component_name = substr( $bp->bp_nav[ $component_id ]['name'], 0, $span - 1 ); } else { $component_name = $bp->bp_nav[ $component_id ]['name']; } // Fall back on the component ID } elseif ( ! empty( $bp->{$component_id}->id ) ) { $component_name = ucwords( $bp->{$component_id}->id ); } // Append action name if we're on a member component sub-page if ( ! empty( $bp->bp_options_nav[ $component_id ] ) && ! empty( $bp->canonical_stack['action'] ) ) { $component_subnav_name = wp_filter_object_list( $bp->bp_options_nav[ $component_id ], array( 'slug' => bp_current_action() ), 'and', 'name' ); if ( $component_subnav_name ) { $component_subnav_name = array_shift( $component_subnav_name ); } else { $component_subnav_name = ''; } } else { $component_subnav_name = ''; } // If on the user profile's landing page, just use the fullname if ( bp_is_current_component( $bp->default_component ) && bp_get_requested_url() === bp_displayed_user_domain() ) { $title = bp_get_displayed_user_fullname(); // Use component name on member pages } else { // If we have a subnav name, add it separately for localization if ( ! empty( $component_subnav_name ) ) { // translators: construct the page title. 1 = user name, 2 = component name, 3 = separator, 4 = component subnav name $title = strip_tags( sprintf( __( '%1$s %3$s %2$s %3$s %4$s', 'buddypress' ), bp_get_displayed_user_fullname(), $component_name, $sep, $component_subnav_name ) ); } else { // translators: construct the page title. 1 = user name, 2 = component name, 3 = separator $title = strip_tags( sprintf( __( '%1$s %3$s %2$s', 'buddypress' ), bp_get_displayed_user_fullname(), $component_name, $sep ) ); } } // A single group } elseif ( bp_is_active( 'groups' ) && ! empty( $bp->groups->current_group ) && ! empty( $bp->bp_options_nav[ $bp->groups->current_group->slug ] ) ) { $subnav = isset( $bp->bp_options_nav[ $bp->groups->current_group->slug ][ bp_current_action() ]['name'] ) ? $bp->bp_options_nav[ $bp->groups->current_group->slug ][ bp_current_action() ]['name'] : ''; // translators: 1 = group name, 2 = group nav section name, 3 = separator $title = sprintf( __( '%1$s %3$s %2$s', 'buddypress' ), $bp->bp_options_title, $subnav, $sep ); // A single item from a component other than groups } elseif ( bp_is_single_item() ) { // translators: 1 = component item name, 2 = component nav section name, 3 = separator $title = sprintf( __( '%1$s %3$s %2$s', 'buddypress' ), $bp->bp_options_title, $bp->bp_options_nav[ bp_current_item() ][ bp_current_action() ]['name'], $sep ); // An index or directory } elseif ( bp_is_directory() ) { $current_component = bp_current_component(); // No current component (when does this happen?) if ( empty( $current_component ) ) { $title = _x( 'Directory', 'component directory title', 'buddypress' ); } else { $title = bp_get_directory_title( $current_component ); } // Sign up page } elseif ( bp_is_register_page() ) { $title = __( 'Create an Account', 'buddypress' ); // Activation page } elseif ( bp_is_activation_page() ) { $title = __( 'Activate your Account', 'buddypress' ); // Group creation page } elseif ( bp_is_group_create() ) { $title = __( 'Create a Group', 'buddypress' ); // Blog creation page } elseif ( bp_is_create_blog() ) { $title = __( 'Create a Site', 'buddypress' ); } // Some BP nav items contain item counts. Remove them $title = preg_replace( '|<span>[0-9]+</span>|', '', $title ); return apply_filters( 'bp_modify_page_title', $title . ' ' . $sep . ' ', $title, $sep, $seplocation ); }
public function filter_menu_items($menu_items, $form_id, $compact) { $form_meta = GFFormsModel::get_form_meta($form_id); $results_fields = $this->get_fields($form_meta); if (false === empty($results_fields)) { $form_id = $form_meta['id']; $link_class = ''; if (rgget('page') == 'gf_new_form') { $link_class = 'gf_toolbar_disabled'; } elseif (rgget('page') == 'gf_entries' && rgget('view') == 'gf_results_' . $this->_slug) { $link_class = 'gf_toolbar_active'; } $id = rgget('id'); if (empty($id)) { //on the form list page, do not use icons $icon = ''; } else { $icon = $this->_icon; if (empty($icon)) { $icon = '<i class="fa fa-bar-chart-o fa-lg"></i>'; } } $sub_menu_items = array(); $sub_menu_items[] = array('label' => $this->_title, 'icon' => $icon, 'title' => esc_html__('View results generated by this form', 'gravityforms'), 'link_class' => $link_class, 'url' => admin_url("admin.php?page=gf_entries&view=gf_results_{$this->_slug}&id={$form_id}"), 'capabilities' => $this->_capabilities); $duplicate_submenus = wp_filter_object_list(rgars($menu_items, 'results/sub_menu_items'), array('label' => $sub_menu_items[0]['label'])); if (count($duplicate_submenus) > 0) { return $menu_items; } // If there's already a menu item with the key "results" then merge the two. if (isset($menu_items['results'])) { $existing_link_class = $menu_items['results']['link_class']; $link_class == empty($existing_link_class) ? $link_class : $existing_link_class; $existing_capabilities = $menu_items['results']['capabilities']; $merged_capabilities = array_merge($existing_capabilities, $this->_capabilities); $existing_sub_menu_items = $menu_items['results']['sub_menu_items']; $merged_sub_menu_items = array_merge($existing_sub_menu_items, $sub_menu_items); $menu_items['results']['link_class'] = $link_class; $menu_items['results']['capabilities'] = $merged_capabilities; $menu_items['results']['sub_menu_items'] = $merged_sub_menu_items; $menu_items['results']['label'] = esc_html__('Results', 'gravityforms'); $menu_items['results']['icon'] = '<i class="fa fa-bar-chart-o fa-lg"></i>'; } else { // so far during the page cycle this is the only menu item for this key $menu_items['results'] = array('label' => $compact ? esc_html__('Results', 'gravityforms') : $this->_title, 'icon' => $icon, 'title' => esc_attr__('View results generated by this form', 'gravityforms'), 'url' => '', 'onclick' => 'return false;', 'menu_class' => 'gf_form_toolbar_results', 'link_class' => $link_class, 'capabilities' => $this->_capabilities, 'sub_menu_items' => $sub_menu_items, 'priority' => 750); } } return $menu_items; }
public static function update_confirmation($form, $lead = null) { if (!is_array(rgar($form, "confirmations"))) { return $form; } // if there is only one confirmation, don't bother with the conditional logic, just return it // this is here mostly to avoid the semi-costly GFFormsModel::create_lead() function unless we really need it if (is_array($form["confirmations"]) && count($form['confirmations']) <= 1) { $form['confirmation'] = reset($form['confirmations']); return $form; } if (empty($lead)) { $lead = GFFormsModel::create_lead($form); } foreach ($form['confirmations'] as $confirmation) { if ($confirmation['isDefault']) { continue; } $logic = rgar($confirmation, "conditionalLogic"); if (GFCommon::evaluate_conditional_logic($logic, $form, $lead)) { $form['confirmation'] = $confirmation; return $form; } } $form['confirmation'] = reset(wp_filter_object_list($form['confirmations'], array('isDefault' => true))); return $form; }