public function wp_get_nav_menu_items($items) { if (doing_action('customize_register')) { // needed since WP 4.3, doing_action available since WP 3.9 return $items; } // the customizer menus does not sort the items and we need them to be sorted before splitting the language switcher usort($items, array($this, 'usort_menu_items')); $new_items = array(); $offset = 0; foreach ($items as $key => $item) { if ($options = get_post_meta($item->ID, '_pll_menu_item', true)) { $i = 0; foreach (pll_the_languages(array_merge(array('raw' => 1), $options)) as $lang) { $lang_item = clone $item; $lang_item->ID = $lang_item->ID . '-' . $lang['slug']; // a unique ID $lang_item->title = $options['show_flags'] && $options['show_names'] ? $lang['flag'] . ' ' . esc_html($lang['name']) : ($options['show_flags'] ? $lang['flag'] : esc_html($lang['name'])); $lang_item->url = $lang['url']; $lang_item->lang = $lang['slug']; // save this for use in nav_menu_link_attributes $lang_item->classes = $lang['classes']; $lang_item->menu_order += $offset + $i++; $new_items[] = $lang_item; } $offset += $i - 1; } else { $item->menu_order += $offset; $new_items[] = $item; } } return $new_items; }
function wpcd_get_customizer_setting($panel_slug, $field_slug, $formatted = false) { if (doing_action('wpcd') || !did_action('wpcd')) { if ('general' === $panel_slug) { $setting = get_theme_mod($field_slug, null); if (!$setting) { $setting = get_option($field_slug, null); } return $setting; } $settings = get_theme_mod($panel_slug, array()); if (!isset($settings[$field_slug])) { $settings = get_option($panel_slug, array()); } return isset($settings[$field_slug]) ? $settings[$field_slug] : null; } $setting = null; $field = \WPDLib\Components\Manager::get($panel_slug . '.*.' . $field_slug, 'WPCD\\Components\\Panel', true); if ($field) { if ('general' === $panel_slug) { $setting = \WPCD\Utility::parse_setting('option' === $field->mode ? get_option($field->slug, null) : get_theme_mod($field->slug, null), $field, $formatted); } else { if ('option' === $field->mode) { $_options = get_option($panel_slug, array()); $setting = \WPCD\Utility::parse_setting(isset($_options[$field->slug]) ? $_options[$field->slug] : null, $field, $formatted); } else { $_thememods = get_theme_mod($panel_slug, array()); $setting = \WPCD\Utility::parse_setting(isset($_thememods[$field->slug]) ? $_thememods[$field->slug] : null, $field, $formatted); } } } return $setting; }
function pinterest_embed_handler($matches, $attr, $url) { // Pinterest's JS handles making the embed $script_src = '//assets.pinterest.com/js/pinit.js'; wp_enqueue_script('pinterest-embed', $script_src, array(), false, true); $path = parse_url($url, PHP_URL_PATH); if (0 === strpos($path, '/pin/')) { $embed_type = 'embedPin'; } elseif (preg_match('#^/([^/]+)/?$#', $path)) { $embed_type = 'embedUser'; } elseif (preg_match('#^/([^/]+)/([^/]+)/?$#', $path)) { $embed_type = 'embedBoard'; } else { if (current_user_can('edit_posts')) { return __('Sorry, that Pinterest URL was not recognized.', 'jetpack'); } return; } $return = sprintf('<a data-pin-do="%s" href="%s"></a>', esc_attr($embed_type), esc_url($url)); // If we're generating an embed view for the WordPress Admin via ajax... if (doing_action('wp_ajax_parse-embed')) { $return .= sprintf('<script src="%s"></script>', esc_url($script_src)); } return $return; }
public function filter_notifications_body($message) { if (doing_action('wpem_new_user_notification_body')) { $id = 'wp_new_user_notification'; } elseif (doing_action('retrieve_password_message')) { $id = 'password_reset'; } elseif (doing_action('wpmu_signup_user_notification_email')) { $id = 'wpmu_signup_user_notification'; } elseif (doing_action('wpmu_signup_blog_notification_email')) { $id = 'wpmu_signup_blog_notification'; } elseif (doing_action('update_welcome_email')) { $id = 'wpmu_welcome_notification'; } $notification = $this->get_notification($id); if (isset($notification['use_custom'])) { remove_filter('wp_mail', 'EM_Mailer::add_default_template'); $message = str_replace('[' . __('system-message', 'wpem') . ']', $message, $notification['body']); if ($notification['mail_format'] == 'html') { $style = get_post_meta($notification['template'], 'wpem_css-box-field', true); add_filter('wp_mail', 'EM_Mailer::add_html_headers'); $message = '<html><head><style>' . $style . '</style><meta name="viewport" content="width=device-width"/><title>' . get_bloginfo('name') . '</title></head><body>' . $message . '</body></html>'; } } return $message; }
/** * Send email on affiliate approval * * @since 1.6 * @param int $affiliate_id The ID of the registered affiliate * @param string $status * @param string $old_status */ function affwp_notify_on_approval($affiliate_id = 0, $status = '', $old_status = '') { if (empty($affiliate_id)) { return; } /** * Only send email if: * Affiliate approval is disabled ( $status = active, $old_status = active ) * Affiliate approval is enabled and the affiliate is accepted ( $status = active, $old_status = pending ) */ if (!('active' == $status && 'active' == $old_status || 'active' == $status && 'pending' == $old_status)) { return; } if (doing_action('affwp_add_affiliate') && empty($_POST['welcome_email'])) { return; } $emails = new Affiliate_WP_Emails(); $emails->__set('affiliate_id', $affiliate_id); $email = affwp_get_affiliate_email($affiliate_id); $subject = affiliate_wp()->settings->get('accepted_subject', __('Affiliate Application Accepted', 'affiliate-wp')); $message = affiliate_wp()->settings->get('accepted_email', ''); if (empty($message)) { $message = sprintf(__('Congratulations %s!', 'affiliate-wp'), affiliate_wp()->affiliates->get_affiliate_name($affiliate_id)) . "\n\n"; $message .= sprintf(__('Your affiliate application on %s has been accepted!', 'affiliate-wp'), home_url()) . "\n\n"; $message .= sprintf(__('Log into your affiliate area at %s', 'affiliate-wp'), affiliate_wp()->login->get_login_url()) . "\n\n"; } // $args is setup for backwards compatibility with < 1.6 $args = array('affiliate_id' => $affiliate_id); $subject = apply_filters('affwp_application_accepted_subject', $subject, $args); $message = apply_filters('affwp_application_accepted_email', $message, $args); $emails->send($email, $subject, $message); }
function enlightenment_glyphicons_author_posts_link_args($args) { if (!is_single() || doing_action('enlightenment_entry_header')) { $args['format'] = '<span class="glyphicon glyphicon-user"></span> ' . $args['format']; } return $args; }
/** * Splits the one item of backend in several items on frontend * take care to menu_order as it is used later in wp_nav_menu * * @since 1.1.1 * * @param array $items menu items * @return array modified items */ public function wp_get_nav_menu_items($items) { if (doing_action('customize_register')) { // needed since WP 4.3, doing_action available since WP 3.9 return $items; } // The customizer menus does not sort the items and we need them to be sorted before splitting the language switcher usort($items, array($this, 'usort_menu_items')); $new_items = array(); $offset = 0; foreach ($items as $key => $item) { if ($options = get_post_meta($item->ID, '_pll_menu_item', true)) { $i = 0; $switcher = new PLL_Switcher(); $args = array_merge(array('raw' => 1), $options); $the_languages = $switcher->the_languages(PLL()->links, $args); // parent item for dropdown if (!empty($options['dropdown'])) { $item->title = $options['show_flags'] && $options['show_names'] ? $this->curlang->flag . ' ' . esc_html($this->curlang->name) : ($options['show_flags'] ? $this->curlang->flag : esc_html($this->curlang->name)); $item->url = ''; $item->classes = array('pll-parent-menu-item'); $new_items[] = $item; $offset++; } foreach ($the_languages as $lang) { $lang_item = clone $item; $lang_item->ID = $lang_item->ID . '-' . $lang['slug']; // A unique ID $lang_item->title = $options['show_flags'] && $options['show_names'] ? $lang['flag'] . '<span style="margin-left:0.3em;">' . esc_html($lang['name']) . '</span>' : ($options['show_flags'] ? $lang['flag'] : esc_html($lang['name'])); $lang_item->url = $lang['url']; $lang_item->lang = $lang['locale']; // Save this for use in nav_menu_link_attributes $lang_item->classes = $lang['classes']; $lang_item->menu_order += $offset + $i++; if (!empty($options['dropdown'])) { $lang_item->menu_item_parent = $item->db_id; $lang_item->db_id = 0; // to avoid recursion } $new_items[] = $lang_item; } $offset += $i - 1; } else { $item->menu_order += $offset; $new_items[] = $item; } } return $new_items; }
/** * Returns a single specified option of a tab. * * This function uses the WordPress core function `get_option()` to get the options array for the tab. * If the required field option is not available, this function will automatically return its default value. * * @since 0.5.0 * @param string $tab_slug the tab slug to get the option for * @param string $field_slug the field slug to get the option for * @param boolean $formatted whether to return an automatically formatted value, ready for output (default is false) * @return mixed the option */ function wpod_get_option($tab_slug, $field_slug, $formatted = false) { $_options = get_option($tab_slug, array()); if (doing_action('wpod') || !did_action('wpod')) { if (isset($_options[$field_slug])) { return $_options[$field_slug]; } return null; } $option = null; $field = \WPDLib\Components\Manager::get('*.*.' . $tab_slug . '.*.' . $field_slug, 'WPDLib\\Components\\Menu.WPOD\\Components\\Screen', true); if ($field) { $option = \WPOD\Utility::parse_option(isset($_options[$field->slug]) ? $_options[$field->slug] : null, $field, $formatted); } return $option; }
function enlightenment_simmulate_post_format($tab) { global $wp_current_filter, $post, $wp_query; if (doing_action('enlightenment_before_page_builder')) { } elseif ('post_formats' == $tab) { $wp_query = new WP_Query(array('post_format' => 'post-format-' . enlightenment_current_post_format())); do_action_ref_array('wp', array(&$wp_query)); the_post(); if (current_theme_supports('enlightenment-grid-loop')) { if (isset($_GET['format']) && strpos($_GET['format'], '-teaser')) { add_filter('enlightenment_is_lead_post', '__return_false'); } else { add_filter('enlightenment_is_lead_post', '__return_true'); } } do_action('enlightenment_before_entry'); // var_dump( get_post_format( $post->ID ) ); } }
function enlightenment_comments_number_wrap($output, $number) { $args = array('container' => 'h3', 'container_class' => 'comments-title', 'container_id' => '', 'format' => __('%1$s for “%2$s”', 'enlightenment'), 'zero' => __('No Comments', 'enlightenment'), 'one' => __('1 Comment', 'enlightenment'), 'more' => __('% Comments', 'enlightenment')); $args = apply_filters('enlightenment_comments_number_wrap_args', $args); if ($number > 1) { $comments_number = str_replace('%', number_format_i18n($number), $args['more']); } elseif ($number == 0) { $comments_number = $args['zero']; } else { // must be one $comments_number = $args['one']; } if (doing_action('enlightenment_before_comments_list')) { $output = enlightenment_open_tag($args['container'], $args['container_class'], $args['container_id']); $output .= sprintf($args['format'], $comments_number, get_the_title()); $output .= enlightenment_close_tag($args['container']); return $output; } return $comments_number; }
/** * Sets terms for attachment taxonomies through the `save_attachment` AJAX action. * * This is a workaround to handle terms through this AJAX action as it normally does not support * terms. * * This method is hooked into the `add_attachment` and `edit_attachment` actions. * * @since 1.0.0 * @access public * * @param integer $attachment_id The attachment ID. */ public function save_ajax_attachment_taxonomies($attachment_id) { if (!doing_action('wp_ajax_save-attachment')) { return; } if (!isset($_REQUEST['changes'])) { return; } foreach (Attachment_Taxonomies_Core::instance()->get_taxonomies('objects') as $taxonomy) { if (!isset($_REQUEST['changes']['taxonomy-' . $taxonomy->name . '-terms'])) { continue; } $terms = $_REQUEST['changes']['taxonomy-' . $taxonomy->name . '-terms']; if ($taxonomy->hierarchical) { $terms = array_filter(array_map('trim', explode(',', $terms))); } if (current_user_can($taxonomy->cap->assign_terms)) { wp_set_post_terms($attachment_id, $terms, $taxonomy->name); } } }
public function wp_get_nav_menu_items($items) { if (function_exists('doing_action') && doing_action('customize_register') || is_admin()) { // needed since WP 4.3, doing_action available since WP 3.9 return $items; } foreach ($items as $key => $item) { if ($options = get_post_meta($item->ID, '_off_canvas_control_menu_item', true)) { $item->url = ''; if (isset($this->general_settings['sidebars'][$options['off-canvas-control']]) && 1 == $this->general_settings['sidebars'][$options['off-canvas-control']]['enable']) { //$item->title = $options['show_flags'] && $options['show_names'] ? $lang['flag'].' '.esc_html($lang['name']) : ($options['show_flags'] ? $lang['flag'] : esc_html($lang['name'])); $link_classes = $this->link_classes; if (!is_array($link_classes)) { $link_classes = explode(' ', $link_classes); } if (!empty($options['off-canvas-control'])) { $link_classes[] = $this->general_settings['css_prefix'] . '-toggle-' . $options['off-canvas-control']; } if (!is_array($item->classes)) { $item->classes = explode(' ', $item->classes); } $item->classes = array_merge($item->classes, $link_classes); } } } return $items; }
/** * Hook into queries, admin screens, and more! * * @since 0.1.0 */ public function __construct($file = '') { // Setup plugin $this->file = $file; $this->url = plugin_dir_url($this->file); $this->path = plugin_dir_path($this->file); $this->basename = plugin_basename($this->file); $this->fancy = apply_filters("wp_fancy_term_{$this->meta_key}", true); // Only look for taxonomies if not already set if (empty($this->taxonomies)) { $this->taxonomies = $this->get_taxonomies(); } // Maybe build db version key if (empty($this->db_version_key)) { $this->db_version_key = "wpdb_term_{$this->meta_key}_version"; } // Register Meta $this->register_meta(); // Queries add_action('create_term', array($this, 'save_meta'), 10, 2); add_action('edit_term', array($this, 'save_meta'), 10, 2); // Term meta orderby add_filter('terms_clauses', array($this, 'terms_clauses'), 10, 3); add_filter('get_terms_orderby', array($this, 'get_terms_orderby'), 10, 1); // Always hook these in, for ajax actions foreach ($this->taxonomies as $value) { // Has column? if (true === $this->has_column) { add_filter("manage_edit-{$value}_columns", array($this, 'add_column_header')); add_filter("manage_{$value}_custom_column", array($this, 'add_column_value'), 10, 3); add_filter("manage_edit-{$value}_sortable_columns", array($this, 'sortable_columns')); } // Has fields? if (true === $this->has_fields) { add_action("{$value}_add_form_fields", array($this, 'add_form_field')); add_action("{$value}_edit_form_fields", array($this, 'edit_form_field')); } } // ajax actions add_action("wp_ajax_{$this->meta_key}_terms", array($this, 'ajax_update')); // Only blog admin screens if (is_blog_admin() || doing_action('wp_ajax_inline_save_tax')) { // Every admin page add_action('admin_init', array($this, 'admin_init')); // Bail if taxonomy does not include colors if (!empty($_REQUEST['taxonomy']) && in_array($_REQUEST['taxonomy'], $this->taxonomies, true)) { add_action('load-edit-tags.php', array($this, 'edit_tags_page')); add_action('load-term.php', array($this, 'term_page')); } } // Pass ths object into an action do_action("wp_term_meta_{$this->meta_key}_init", $this); }
/** * @ticket 14994 */ function test_doing_action() { global $wp_current_filter; $wp_current_filter = array(); // Set to an empty array first $this->assertFalse(doing_action()); // No action is passed in, and no filter is being processed $this->assertFalse(doing_action('testing')); // Action is passed in but not being processed $wp_current_filter[] = 'testing'; $this->assertTrue(doing_action()); // No action is passed in, and a filter is being processed $this->assertTrue(doing_action('testing')); // Action is passed in and is being processed $this->assertFalse(doing_action('something_else')); // Action is passed in but not being processed $wp_current_filter = array(); }
/** * Enqueue option type scripts and styles * * All parameters are optional and will be populated with defaults * @param string $id * @param array $option * @param array $data * @return bool */ public final function enqueue_static($id = '', $option = array(), $data = array()) { if (!doing_action('admin_enqueue_scripts') && !did_action('admin_enqueue_scripts')) { /** * Do not wp_enqueue/register_...() because at this point not all handles has been registered * and maybe they are used in dependencies in handles that are going to be enqueued. * So as a result some handles will not be equeued because of not registered dependecies. */ return; } static $option_types_static_enqueued = false; if (!$option_types_static_enqueued) { wp_enqueue_style('fw-option-types', fw_get_framework_directory_uri('/static/css/option-types.css'), array('fw', 'qtip'), fw()->manifest->get_version()); wp_enqueue_script('fw-option-types', fw_get_framework_directory_uri('/static/js/option-types.js'), array('fw-events', 'qtip'), fw()->manifest->get_version(), true); $option_types_static_enqueued = true; } if ($this->static_enqueued) { return false; } $this->prepare($id, $option, $data); $call_next_time = $this->_enqueue_static($id, $option, $data); $this->static_enqueued = !$call_next_time; return $call_next_time; }
/** * Hook into queries, admin screens, and more! * * @since 0.1.0 */ public function __construct($file = '') { // Setup plugin $this->file = $file; $this->url = plugin_dir_url($this->file); $this->path = plugin_dir_path($this->file); $this->basename = plugin_basename($this->file); $this->taxonomies = $this->get_taxonomies(); $this->fancy = apply_filters("wp_fancy_term_{$this->meta_key}", true); // Register Meta $this->register_meta(); // Queries add_action('create_term', array($this, 'save_meta'), 10, 2); add_action('edit_term', array($this, 'save_meta'), 10, 2); // Term meta orderby add_filter('terms_clauses', array($this, 'terms_clauses'), 10, 3); add_filter('get_terms_orderby', array($this, 'get_terms_orderby'), 10, 1); // Always hook these in, for ajax actions foreach ($this->taxonomies as $value) { // Has column? if (true === $this->has_column) { add_filter("manage_edit-{$value}_columns", array($this, 'add_column_header')); add_filter("manage_{$value}_custom_column", array($this, 'add_column_value'), 10, 3); add_filter("manage_edit-{$value}_sortable_columns", array($this, 'sortable_columns')); } // Has fields? if (true === $this->has_fields) { add_action("{$value}_add_form_fields", array($this, 'add_form_field')); add_action("{$value}_edit_form_fields", array($this, 'edit_form_field')); } } // ajax actions add_action("wp_ajax_{$this->meta_key}_terms", array($this, 'ajax_update')); // Only blog admin screens if (is_blog_admin() || doing_action('wp_ajax_inline_save_tax')) { add_action('admin_init', array($this, 'admin_init')); add_action('load-edit-tags.php', array($this, 'edit_tags')); } }
/** * Display title tag with contents. * * @ignore * @since 4.1.0 * @access private * * @see wp_title() */ function _wp_render_title_tag() { if (!current_theme_supports('title-tag')) { return; } // This can only work internally on wp_head. if (!did_action('wp_head') && !doing_action('wp_head')) { return; } echo '<title>' . wp_title('|', false, 'right') . "</title>\n"; }
function enlightenment_post_thumbnail_size($size) { if ('full-screen' == enlightenment_current_sidebar_name() && doing_action('enlightenment_custom_before_entry_header')) { global $enlightenment_custom_query_name; if ('custom_query_widget_slider' == $enlightenment_custom_query_name) { return 'full'; } } elseif (!enlightenment_is_lead_post()) { return 'enlightenment-teaser-thumb'; } elseif ('small' == enlightenment_theme_option('thumbnails_size')) { return 'thumbnail'; } return 'enlightenment-blog-thumb'; }
/** * Disable New Relic's browser metrics * * Removes NR's JavaScript for tracking browser metrics, including page load times, Apdex score, and more. * * Must be called at or before the `template_redirect` action. */ function wpcom_vip_disable_new_relic_js() { if (did_action('template_redirect') && !doing_action('template_redirect')) { _doing_it_wrong(__FUNCTION__, 'New Relic’s browser tracking can only be disabled at or before the `template_redirect` action.', '1.0'); return; } if (function_exists('newrelic_disable_autorum')) { newrelic_disable_autorum(); } }
/** * Hook into queries, admin screens, and more! * * @since 0.1.0 */ public function __construct() { // Setup plugin $this->file = __FILE__; $this->url = plugin_dir_url($this->file); $this->path = plugin_dir_path($this->file); $this->basename = plugin_basename($this->file); $this->fancy = apply_filters('wp_fancy_term_order', true); // Queries add_filter('get_terms_orderby', array($this, 'get_terms_orderby'), 10, 2); add_action('create_term', array($this, 'add_term_order'), 10, 2); add_action('edit_term', array($this, 'add_term_order'), 10, 2); // Get visible taxonomies $taxonomies = $this->get_taxonomies(); // Always hook these in, for ajax actions foreach ($taxonomies as $value) { // Unfancy gets the column if (false === $this->fancy) { add_filter("manage_edit-{$value}_columns", array($this, 'add_column_header')); add_filter("manage_{$value}_custom_column", array($this, 'add_column_value'), 10, 3); add_filter("manage_edit-{$value}_sortable_columns", array($this, 'sortable_columns')); } add_action("{$value}_add_form_fields", array($this, 'term_order_add_form_field')); add_action("{$value}_edit_form_fields", array($this, 'term_order_edit_form_field')); } // Ajax actions add_action('wp_ajax_reordering_terms', array($this, 'ajax_reordering_terms')); // Only blog admin screens if (is_blog_admin() || doing_action('wp_ajax_inline_save_tax')) { add_action('admin_init', array($this, 'admin_init')); add_action('load-edit-tags.php', array($this, 'edit_tags')); } }
/** * WP 4.3以下用の wp_title() 互換関数 (WP 4.3相当) * * @param string $sep 区切り文字 * @param bool $display 出力の有無 * @param string $seplocation 区切り文字の位置 * * @return string|null タイトル */ function st_wp_title($sep = '»', $display = true, $seplocation = '') { global $wp_locale, $page, $paged; $m = get_query_var('m'); $year = get_query_var('year'); $monthnum = get_query_var('monthnum'); $day = get_query_var('day'); $search = get_query_var('s'); $title = ''; $t_sep = '%WP_TITILE_SEP%'; // 投稿 if (is_single() || is_home() && !is_front_page() || is_page() && !is_front_page()) { $title = single_post_title('', false); } // 投稿タイプアーカイブ if (is_post_type_archive()) { $post_type = get_query_var('post_type'); if (is_array($post_type)) { $post_type = reset($post_type); } $post_type_object = get_post_type_object($post_type); if (!$post_type_object->has_archive) { $title = post_type_archive_title('', false); } } // カテゴリー, タグ if (is_category() || is_tag()) { $title = single_term_title('', false); } // タクソノミー if (is_tax()) { $term = get_queried_object(); if ($term) { $tax = get_taxonomy($term->taxonomy); $title = single_term_title($tax->labels->name . $t_sep, false); } } // 著者 if (is_author() && !is_post_type_archive()) { $author = get_queried_object(); if ($author) { $title = $author->display_name; } } // 投稿タイプアーカイブ (has_archive) if (is_post_type_archive() && $post_type_object->has_archive) { $title = post_type_archive_title('', false); } // 月 if (is_archive() && !empty($m)) { $my_year = substr($m, 0, 4); $my_month = $wp_locale->get_month(substr($m, 4, 2)); $my_day = intval(substr($m, 6, 2)); $title = $my_year . ($my_month ? $t_sep . $my_month : '') . ($my_day ? $t_sep . $my_day : ''); } // 年 if (is_archive() && !empty($year)) { $title = $year; if (!empty($monthnum)) { $title .= $t_sep . $wp_locale->get_month($monthnum); } if (!empty($day)) { $title .= $t_sep . zeroise($day, 2); } } // 検索 if (is_search()) { $title = sprintf(__('Search Results %1$s %2$s', 'affinger'), $t_sep, strip_tags($search)); } // 404 if (is_404()) { $title = __('Page not found', 'affinger'); } $prefix = ''; if (!empty($title)) { $prefix = " {$sep} "; } $title_array = apply_filters('wp_title_parts', explode($t_sep, $title)); if ($seplocation === 'right') { $title_array = array_reverse($title_array); $title = implode(" {$sep} ", $title_array) . $prefix; } else { $title = $prefix . implode(" {$sep} ", $title_array); } // wp_head() 以外はフィルターを適用 if (!did_action('wp_head') && !doing_action('wp_head')) { $title = apply_filters('wp_title', $title, $sep, $seplocation); } if ($display) { echo $title; } else { return $title; } }
function wptalents_is_oembed() { return did_action('wptalents_oembed_output') || doing_action('wptalents_oembed_output'); }
public function addThemeFeature($name, array $params = array()) { switch ($name) { case 'query-vars': extract(array_merge(array('qvars' => array()), $params)); if (!empty($qvars)) { add_action('query_vars', function ($_qvars) use($qvars) { return array_merge($_qvars, $qvars); }); } break; case 'retina-image-size': add_action('init', function () { foreach ($_ = $GLOBALS['_wp_additional_image_sizes'] as $name => $image_size) { if (strpos($name, '@2x') === false) { add_image_size($name . '@2x', $image_size['width'] * 2, $image_size['height'] * 2, $image_size['crop']); } } add_image_size('thumbnail@2x', get_option('thumbnail_size_w') * 2, get_option('thumbnail_size_h') * 2, (bool) get_option('thumbnail_crop')); add_image_size('medium@2x', get_option('medium_size_w') * 2, get_option('medium_size_h') * 2, false); add_image_size('large@2x', get_option('large_size_w') * 2, get_option('large_size_h') * 2, false); }); break; case 'x-ua-compatible': if (!is_admin()) { add_action('send_headers', function () { header('X-UA-Compatible: IE=edge,chrome=1'); }); } break; case 'nav-menu-current-item': extract(array_merge(array('class' => 'current'), $params)); $filter = function ($items) use($class) { return preg_replace('/([ "\'])(current(?:(?:-menu-|_page_)(?:item|parent|ancestor)|-cat))([ "\'])/i', '\\1' . $class . ' \\2\\3', $items); }; add_filter('wp_nav_menu_items', $filter); add_filter('wp_list_pages', $filter); add_filter('wp_list_categories', $filter); break; case 'force-img-caption-shortcode-filter': add_filter('the_content', array($this, '__filterForceImgCaptionShortcodeFilter'), 5); break; case 'tinymce-shortcodes-menu': if (!isset($this->features['shortcodes'])) { $this->features['shortcodes'] = array(); } $this->features['shortcodes'] = array_merge($this->features['shortcodes'], $params); break; case 'widget-unwrapped-text': extract(array_merge(array('on_setup_options' => null, 'on_html' => null, 'on_output_html' => null), $params)); Widgets\Widget::$_on_setup_options['unwrapped-text'] = $on_setup_options; Widgets\Widget::$_on_html['unwrapped-text'] = $on_html; Widgets\Widget::$_on_output_html['unwrapped-text'] = $on_output_html; if (doing_action('widgets_init')) { register_widget('\\Drone\\Widgets\\Widget\\UnwrappedText'); } else { _doing_it_wrong(__METHOD__, 'Use inside widgets_init action.', '5.0'); add_action('widgets_init', function () { register_widget('\\Drone\\Widgets\\Widget\\UnwrappedText'); }); } break; case 'widget-page': extract(array_merge(array('on_setup_options' => null, 'on_html' => null, 'on_output_html' => null), $params)); Widgets\Widget::$_on_setup_options['page'] = $on_setup_options; Widgets\Widget::$_on_html['page'] = $on_html; Widgets\Widget::$_on_output_html['page'] = $on_output_html; if (doing_action('widgets_init')) { register_widget('\\Drone\\Widgets\\Widget\\Page'); } else { _doing_it_wrong(__METHOD__, 'Use inside widgets_init action.', '5.0'); add_action('widgets_init', function () { register_widget('\\Drone\\Widgets\\Widget\\Page'); }); } break; case 'widget-posts-list': extract(array_merge(array('on_setup_options' => null, 'on_html' => null, 'on_output_html' => null, 'on_post' => null), $params)); Widgets\Widget::$_on_setup_options['posts-list'] = $on_setup_options; Widgets\Widget::$_on_html['posts-list'] = $on_html; Widgets\Widget::$_on_output_html['posts-list'] = $on_output_html; Widgets\Widget\PostsList::$_on_post = $on_post; if (doing_action('widgets_init')) { register_widget('\\Drone\\Widgets\\Widget\\PostsList'); } else { _doing_it_wrong(__METHOD__, 'Use inside widgets_init action.', '5.0'); add_action('widgets_init', function () { register_widget('\\Drone\\Widgets\\Widget\\PostsList'); }); } break; case 'widget-twitter': extract(array_merge(array('on_setup_options' => null, 'on_html' => null, 'on_output_html' => null, 'on_tweet' => null), $params)); Widgets\Widget::$_on_setup_options['twitter'] = $on_setup_options; Widgets\Widget::$_on_html['twitter'] = $on_html; Widgets\Widget::$_on_output_html['twitter'] = $on_output_html; Widgets\Widget\Twitter::$_on_tweet = $on_tweet; if (doing_action('widgets_init')) { register_widget('\\Drone\\Widgets\\Widget\\Twitter'); } else { _doing_it_wrong(__METHOD__, 'Use inside widgets_init action.', '5.0'); add_action('widgets_init', function () { register_widget('\\Drone\\Widgets\\Widget\\Twitter'); }); } break; case 'widget-flickr': extract(array_merge(array('on_setup_options' => null, 'on_html' => null, 'on_output_html' => null, 'on_photo' => null), $params)); Widgets\Widget::$_on_setup_options['flickr'] = $on_setup_options; Widgets\Widget::$_on_html['flickr'] = $on_html; Widgets\Widget::$_on_output_html['flickr'] = $on_output_html; Widgets\Widget\Flickr::$_on_photo = $on_photo; if (doing_action('widgets_init')) { register_widget('\\Drone\\Widgets\\Widget\\Flickr'); } else { _doing_it_wrong(__METHOD__, 'Use inside widgets_init action.', '5.0'); add_action('widgets_init', function () { register_widget('\\Drone\\Widgets\\Widget\\Flickr'); }); } break; case 'widget-facebook-like-box': if (doing_action('widgets_init')) { register_widget('\\Drone\\Widgets\\Widget\\FacebookLikeBox'); } else { _doing_it_wrong(__METHOD__, 'Use inside widgets_init action.', '5.0'); add_action('widgets_init', function () { register_widget('\\Drone\\Widgets\\Widget\\FacebookLikeBox'); }); } break; case 'option-favicon': if (!self::$setup_options_lock) { _doing_it_wrong(__METHOD__, 'Use inside onSetupOptions() method.', '5.0'); } extract(array_merge(array('group' => 'other', 'name' => 'favicon', 'default' => ''), $params)); $child = $this->theme_options->child($group); if (!$child->isGroup()) { break; } $option = $child->addOption('image', $name, '', __('Favicon image', $this->domain), sprintf(__("Paste favicon's URL or select/upload an image (%s).", $this->domain), '<code>png</code>, <code>gif</code>, <code>ico</code>'), array('title' => __('Select icon', $this->domain), 'filter' => 'png|gif|ico')); add_action('wp_head', function () use($option, $default) { if ($href = !$option->isEmpty() ? $option->value : $default) { echo '<link rel="shortcut icon" href="' . $href . '" />'; } }); break; case 'option-feed-url': if (!self::$setup_options_lock) { _doing_it_wrong(__METHOD__, 'Use inside onSetupOptions() method.', '5.0'); } extract(array_merge(array('group' => 'other', 'name' => 'feed_url'), $params)); $child = $this->theme_options->child($group); if (!$child->isGroup()) { break; } $option = $child->addOption('codeline', $name, '', __('Alternative feed URL', $this->domain), __('E.g. FeedBurner.', $this->domain)); add_filter('feed_link', function ($output, $feed) use($option) { return !$option->isEmpty() && stripos($output, 'comments') === false ? $option->value : $output; }, 10, 2); break; case 'option-tracking-code': if (!self::$setup_options_lock) { _doing_it_wrong(__METHOD__, 'Use inside onSetupOptions() method.', '5.0'); } extract(array_merge(array('group' => 'other', 'name' => 'tracking_code'), $params)); $child = $this->theme_options->child($group); if (!$child->isGroup()) { break; } $option = $child->addOption('code', $name, '', __('Tracking code', $this->domain), __('E.g. Google Analitycs.', $this->domain)); add_action('wp_head', function () use($option) { echo $option->value; }, 100); break; case 'option-ogp': if (!self::$setup_options_lock) { _doing_it_wrong(__METHOD__, 'Use inside onSetupOptions() method.', '5.0'); } extract($params = array_merge(array('group' => 'other', 'name' => 'ogp'), $params)); $child = $this->theme_options->child($group); if (!$child->isGroup()) { break; } $child = $child->addGroup($name, __('Open Graph Protocol', $this->domain)); $enabled = $child->addOption('boolean', 'enabled', true, '', '', array('caption' => __('Enabled', $this->domain))); $child->addOption('image', 'image', '', __('Default image', $this->domain), '', array('owner' => $enabled, 'indent' => true)); $this->features['ogp'] = $params; add_action('wp_head', array($this, '__actionOGP'), 1); break; case 'option-custom-css': if (!self::$setup_options_lock) { _doing_it_wrong(__METHOD__, 'Use inside onSetupOptions() method.', '5.0'); } extract(array_merge(array('group' => 'advanced', 'name' => 'custom_css'), $params)); $child = $this->theme_options->child($group); if (!$child->isGroup()) { break; } $option = $child->addOption('code', $name, '', __('Custom CSS code', $this->domain), '', array('error_value' => function ($o, $v) { return (bool) preg_match('#^<style[^>]*>.*</style>$#is', trim($v)); })); add_action('wp_enqueue_scripts', function () use($option) { if ($option->isEmpty()) { return; } Theme::getInstance()->addDocumentStyle(preg_replace('#^(?:<style[^>]*>)?(.*?)(?:</style>)?$#is', '\\1', $option->value)); }); break; case 'option-custom-js': if (!self::$setup_options_lock) { _doing_it_wrong(__METHOD__, 'Use inside onSetupOptions() method.', '5.0'); } extract(array_merge(array('group' => 'advanced', 'name' => 'custom_js'), $params)); $child = $this->theme_options->child($group); if (!$child->isGroup()) { break; } $option = $child->addOption('code', $name, '', __('Custom JavaScript code', $this->domain), '', array('error_value' => function ($o, $v) { return (bool) preg_match('#^<script[^>]*>.*</script>$#is', trim($v)); })); add_action('wp_enqueue_scripts', function () use($option) { if ($option->isEmpty()) { return; } Theme::getInstance()->addDocumentScript(preg_replace('#^(?:<script[^>]*>)?(.*?)(?:</script>)?$#is', '\\1', $option->value)); }); break; case 'option-contact-form': if (!self::$setup_options_lock) { _doing_it_wrong(__METHOD__, 'Use inside onSetupOptions() method.', '5.0'); } extract($params = array_merge(array('group' => '', 'name' => 'contact_form', 'form_id' => '', 'form_class' => 'contact-form', 'result_var' => 'result', 'message_var' => 'message'), $params)); $child = $this->theme_options->child($group); if (!$child->isGroup()) { break; } $child = $child->addGroup($name, __('Contact form', $this->domain)); $subject_description = '<code>%blogname%</code> - ' . __('blog name', $this->domain) . ', ' . '<code>%blogurl%</code> - ' . __('blog url', $this->domain) . ', ' . '<code>%name%</code> - ' . __('name field', $this->domain) . ', ' . '<code>%email%</code> - ' . __('e-mail field', $this->domain) . ', ' . '<code>%website%</code> - ' . __('website field', $this->domain) . ', ' . '<code>%phone%</code> - ' . __('phone number field', $this->domain) . ', ' . '<code>%subject%</code> - ' . __('subject field', $this->domain) . '.'; $child->addOption('group', 'fields', array('name', 'email', 'subject', 'message'), __('Available form fields', $this->domain), '∗ ' . __('required fields (if present).', $this->domain), array('options' => array('name' => __('Name', $this->domain) . '<sup>∗</sup>', 'email' => __('E-mail', $this->domain) . '<sup>∗</sup>', 'website' => __('Website', $this->domain), 'phone' => __('Phone number', $this->domain), 'subject' => __('Subject', $this->domain), 'message' => __('Message', $this->domain) . '<sup>∗</sup>', 'captcha' => sprintf('<a href="http://wordpress.org/plugins/captcha/">%s</a><sup>∗</sup>', __('Captcha', $this->domain))), 'multiple' => true, 'sortable' => true, 'disabled' => $this->isPluginActive('captcha') ? array('email', 'message') : array('email', 'message', 'captcha'))); $child->addOption('text', 'subject', '[%blogname%] %subject%', __('E-mail subject', $this->domain), $subject_description, array()); $child->addOption('codeline', 'to', get_option('admin_email'), __('Recipient e-mail address', $this->domain), '', array()); $child->addOption('select', 'from', 'admin', __('Sender e-mail address', $this->domain), __("Some servers allow only for sending emails from their own domain, so in that case make sure it's the proper email.", $this->domain), array('options' => array('admin' => sprintf('%s (%s)', __('WordPress settings e-mail', $this->domain), get_option('admin_email')), 'to' => __('Recipient e-mail address', $this->domain), 'field' => __('E-mail form field', $this->domain)))); $settings_default = array('from_header'); $settings_disabled = array(); if ($this->isPluginActive('akismet')) { $settings_default[] = 'akismet'; } else { $settings_disabled[] = 'akismet'; } $child->addOption('group', 'settings', $settings_default, __('Advanced settings', $this->domain), '', array('options' => array('akismet' => sprintf(__('Protect from spam with %s', $this->domain), '<a href="http://wordpress.org/plugins/akismet/">Akismet</a>'), 'from_header' => sprintf(__('Override %s header with Name field', $this->domain), '<code>From</code>')), 'multiple' => true, 'disabled' => $settings_disabled)); $this->features['contact-form'] = array_merge($params, array('action' => $action = $this->theme->id . '_contact_form')); add_action("wp_ajax_nopriv_{$action}", array($this, '__actionWPAjaxContactForm')); add_action("wp_ajax_{$action}", array($this, '__actionWPAjaxContactForm')); break; case 'shortcode-page': new Shortcodes\Shortcode\Page(); break; case 'shortcode-noformat': _deprecated_argument(__METHOD__, '5.0', 'Use shortcode-no-format istead.'); case 'shortcode-no-format': new Shortcodes\Shortcode\NoFormat(); break; } }
/** * Check WordPress version against the newest version. * * The WordPress version, PHP version, and Locale is sent. Checks against the * WordPress server at api.wordpress.org server. Will only check if WordPress * isn't installing. * * @since 2.3.0 * @global string $wp_version Used to check against the newest WordPress version. * @global wpdb $wpdb * @global string $wp_local_package * * @param array $extra_stats Extra statistics to report to the WordPress.org API. * @param bool $force_check Whether to bypass the transient cache and force a fresh update check. Defaults to false, true if $extra_stats is set. */ function wp_version_check($extra_stats = array(), $force_check = false) { if (wp_installing()) { return; } global $wp_version, $wpdb, $wp_local_package; // include an unmodified $wp_version include ABSPATH . WPINC . '/version.php'; $php_version = phpversion(); $current = get_site_transient('update_core'); $translations = wp_get_installed_translations('core'); // Invalidate the transient when $wp_version changes if (is_object($current) && $wp_version != $current->version_checked) { $current = false; } if (!is_object($current)) { $current = new stdClass(); $current->updates = array(); $current->version_checked = $wp_version; } if (!empty($extra_stats)) { $force_check = true; } // Wait 60 seconds between multiple version check requests $timeout = 60; $time_not_changed = isset($current->last_checked) && $timeout > time() - $current->last_checked; if (!$force_check && $time_not_changed) { return; } /** * Filter the locale requested for WordPress core translations. * * @since 2.8.0 * * @param string $locale Current locale. */ $locale = apply_filters('core_version_check_locale', get_locale()); // Update last_checked for current to prevent multiple blocking requests if request hangs $current->last_checked = time(); set_site_transient('update_core', $current); if (method_exists($wpdb, 'db_version')) { $mysql_version = preg_replace('/[^0-9.].*/', '', $wpdb->db_version()); } else { $mysql_version = 'N/A'; } if (is_multisite()) { $user_count = get_user_count(); $num_blogs = get_blog_count(); $wp_install = network_site_url(); $multisite_enabled = 1; } else { $user_count = count_users(); $user_count = $user_count['total_users']; $multisite_enabled = 0; $num_blogs = 1; $wp_install = home_url('/'); } $query = array('version' => $wp_version, 'php' => $php_version, 'locale' => $locale, 'mysql' => $mysql_version, 'local_package' => isset($wp_local_package) ? $wp_local_package : '', 'blogs' => $num_blogs, 'users' => $user_count, 'multisite_enabled' => $multisite_enabled, 'initial_db_version' => get_site_option('initial_db_version')); $post_body = array('translations' => wp_json_encode($translations)); if (is_array($extra_stats)) { $post_body = array_merge($post_body, $extra_stats); } $url = $http_url = 'http://api.wordpress.org/core/version-check/1.7/?' . http_build_query($query, null, '&'); if ($ssl = wp_http_supports(array('ssl'))) { $url = set_url_scheme($url, 'https'); } $options = array('timeout' => defined('DOING_CRON') && DOING_CRON ? 30 : 3, 'user-agent' => 'WordPress/' . $wp_version . '; ' . home_url('/'), 'headers' => array('wp_install' => $wp_install, 'wp_blog' => home_url('/')), 'body' => $post_body); $response = wp_remote_post($url, $options); if ($ssl && is_wp_error($response)) { trigger_error(__('An unexpected error occurred. Something may be wrong with WordPress.org or this server’s configuration. If you continue to have problems, please try the <a href="https://wordpress.org/support/">support forums</a>.') . ' ' . __('(WordPress could not establish a secure connection to WordPress.org. Please contact your server administrator.)'), headers_sent() || WP_DEBUG ? E_USER_WARNING : E_USER_NOTICE); $response = wp_remote_post($http_url, $options); } if (is_wp_error($response) || 200 != wp_remote_retrieve_response_code($response)) { return; } $body = trim(wp_remote_retrieve_body($response)); $body = json_decode($body, true); if (!is_array($body) || !isset($body['offers'])) { return; } $offers = $body['offers']; foreach ($offers as &$offer) { foreach ($offer as $offer_key => $value) { if ('packages' == $offer_key) { $offer['packages'] = (object) array_intersect_key(array_map('esc_url', $offer['packages']), array_fill_keys(array('full', 'no_content', 'new_bundled', 'partial', 'rollback'), '')); } elseif ('download' == $offer_key) { $offer['download'] = esc_url($value); } else { $offer[$offer_key] = esc_html($value); } } $offer = (object) array_intersect_key($offer, array_fill_keys(array('response', 'download', 'locale', 'packages', 'current', 'version', 'php_version', 'mysql_version', 'new_bundled', 'partial_version', 'notify_email', 'support_email', 'new_files'), '')); } $updates = new stdClass(); $updates->updates = $offers; $updates->last_checked = time(); $updates->version_checked = $wp_version; if (isset($body['translations'])) { $updates->translations = $body['translations']; } set_site_transient('update_core', $updates); if (!empty($body['ttl'])) { $ttl = (int) $body['ttl']; if ($ttl && time() + $ttl < wp_next_scheduled('wp_version_check')) { // Queue an event to re-run the update check in $ttl seconds. wp_schedule_single_event(time() + $ttl, 'wp_version_check'); } } // Trigger a background updates check if running non-interactively, and we weren't called from the update handler. if (defined('DOING_CRON') && DOING_CRON && !doing_action('wp_maybe_auto_update')) { do_action('wp_maybe_auto_update'); } }
/** * Allows plugins to submit security reports. * * @param string $type Report type (login_form, backup, file_scanning, spam) * @param string $plugin_file Plugin __FILE__, so that we can pull plugin data * @param array $args See definitions above */ public static function submit_security_report($type = '', $plugin_file = '', $args = array()) { if (!doing_action('jetpack_security_report')) { return new WP_Error('not_collecting_report', 'Not currently collecting security reports. Please use the jetpack_security_report hook.'); } if (!is_string($type) || !is_string($plugin_file)) { return new WP_Error('invalid_security_report', 'Invalid Security Report'); } if (!function_exists('get_plugin_data')) { include ABSPATH . 'wp-admin/includes/plugin.php'; } //Get rid of any non-allowed args $args = array_intersect_key($args, array_flip(array('blocked', 'last', 'next', 'status', 'message'))); $plugin = get_plugin_data($plugin_file); if (!$plugin['Name']) { return new WP_Error('security_report_missing_plugin_name', 'Invalid Plugin File Provided'); } // Sanitize everything to make sure we're not syncing something wonky $type = sanitize_key($type); $args['plugin'] = $plugin; // Cast blocked, last and next as integers. // Last and next should be in unix timestamp format if (isset($args['blocked'])) { $args['blocked'] = (int) $args['blocked']; } if (isset($args['last'])) { $args['last'] = (int) $args['last']; } if (isset($args['next'])) { $args['next'] = (int) $args['next']; } if (!in_array($args['status'], array('ok', 'warning', 'error'))) { $args['status'] = 'ok'; } if (isset($args['message'])) { if ($args['status'] == 'ok') { unset($args['message']); } $allowed_html = array('a' => array('href' => array(), 'title' => array()), 'em' => array(), 'strong' => array()); $args['message'] = wp_kses($args['message'], $allowed_html); } $plugin_name = $plugin['Name']; self::$security_report[$type][$plugin_name] = $args; }
function epl_remove_single_thumbnail($html, $post_id, $post_thumbnail_id, $size, $attr) { if (is_admin()) { return $html; } if (is_epl_post()) { // allow single listing images as well as widget images if (doing_action('epl_property_featured_image') || doing_action('epl_property_widgets_featured_image')) { } else { $html = ''; } } return $html; }
public function __construct() { if (!doing_action('init') && !did_action('init')) { add_action('init', array($this, 'register')); } }
function enlightenment_bootstrap_search_form_wrap($output) { if (doing_action('enlightenment_header')) { $before = '<div class="dropdown searchform-dropdown"> <a id="toggle-search-form" data-toggle="dropdown" href="#" aria-expanded="false"><span class="glyphicon glyphicon-search"></span></a> <ul class="dropdown-menu" role="menu" aria-labelledby="toggle-search-form"> <li>'; $after = '</li> </ul> </div>'; $output = $before . $output . $after; } return $output; }
/** * Render option enclosed in backend design * * @param string $id * @param array $option * @param array $data * @param string $design default or taxonomy * * @return string */ public function render_option($id, $option, $data = array(), $design = null) { if (empty($design)) { $design = $this->default_render_design; } if (!doing_action('admin_enqueue_scripts') && !did_action('admin_enqueue_scripts')) { /** * Do not wp_enqueue/register_...() because at this point not all handles has been registered * and maybe they are used in dependencies in handles that are going to be enqueued. * So as a result some handles will not be equeued because of not registered dependecies. */ } else { $this->register_static(); } if (!in_array($design, $this->available_render_designs)) { trigger_error('Invalid render design specified: ' . $design, E_USER_WARNING); $design = 'post'; } if (!isset($data['id_prefix'])) { $data['id_prefix'] = FW_Option_Type::get_default_id_prefix(); } if (isset($option['option_handler']) && $option['option_handler'] instanceof FW_Option_Handler) { /* * if the option has a custom option_handler * then the handler provides the option's value */ $data['value'] = $option['option_handler']->get_option_value($id, $option, $data); } return fw_render_view(fw_get_framework_directory('/views/backend-option-design-' . $design . '.php'), array('id' => $id, 'option' => $option, 'data' => $data)); }
/** * Check if there the aggregate data cron is executed * @return bool */ private function is_running_cron() { return doing_action('yst_ga_aggregate_data') && defined('DOING_CRON') && DOING_CRON; }