/** * @param Request $request * @param $result * * @dataProvider provideGetActionTestData */ public function testGetCorrectAction(Request $request, $result) { app(HttpKernelContract::class)->handle($request); $this->assertSame($result, \Active::getAction()); $this->assertSame($result, app('active')->getAction()); $this->assertSame($result, current_action()); }
public static function build_page() { $page_hook = current_action(); $page_attr = array_key_exists($page_hook, self::$pages['parent']) ? self::$pages['parent'][$page_hook] : self::$pages['child'][$page_hook]; $page_content = is_array($page_attr['function']) ? $page_attr['function'][0] . '::' . $page_attr['function'][1] : $page_attr['function']; ?> <div id = "<?php echo $page_attr['menu_slug']; ?> " class="cherry-page-wrapper"> <?php if ($page_attr['page_title']) { ?> <div class="cherry-page-title"> <span><?php echo $page_attr['page_title']; ?> </span> </div> <?php } echo $page_attr['before_content']; ?> <div class="cherry-page-content cherry-ui-core"> <?php call_user_func($page_content); ?> </div> </div> <?php echo $page_attr['after_content']; }
function popmake_render_popup_theme_styles() { if (current_action() == 'wp_head' && popmake_get_option('disable_popup_theme_styles', false) || current_action() == 'admin_head' && !popmake_is_admin_popup_page()) { return; } $styles = get_transient('popmake_theme_styles'); if (!$styles) { $styles = ''; $google_fonts = array(); foreach (popmake_get_all_popup_themes() as $theme) { $theme_styles = popmake_render_theme_styles($theme->ID); $google_fonts = array_merge($google_fonts, popmake_get_popup_theme_google_fonts($theme->ID)); if ($theme_styles != '') { $styles .= "/* Popup Theme " . $theme->ID . ": " . $theme->post_title . " */\r\n"; $styles .= $theme_styles; } } if (!empty($google_fonts)) { $link = "//fonts.googleapis.com/css?family="; foreach ($google_fonts as $font_family => $variants) { if ($link != "//fonts.googleapis.com/css?family=") { $link .= "|"; } $link .= $font_family; if (!empty($variants)) { $link .= ":"; $link .= implode(',', $variants); } } $styles = "/* Popup Google Fonts */\r\n@import url('{$link}');\r\n\r\n" . $styles; } set_transient('popmake_theme_styles', $styles, 7 * DAY_IN_SECONDS); } echo '<style id="popup-maker-themes" type="text/css">' . $styles . '</style>'; }
function popmake_gforms_force_ajax() { if (current_action() == 'popmake_popup_before_inner') { add_filter('shortcode_atts_gravityforms', 'popmake_force_gforms_ajax'); } if (current_action() == 'popmake_popup_after_inner') { remove_filter('shortcode_atts_gravityforms', 'popmake_force_gforms_ajax'); } }
/** * Proxy "noop" for the WordPress Action API. * * @param mixed This function may be called on an action. * * @return void|mixed */ public function action_noop() { $action = current_action(); $args = func_get_args(); $this->noop('action', $action); if (count($args)) { return reset($args); } }
public function __construct() { parent::__construct(); view()->share('current_action', 'forum-forum-covers-' . current_action()); $this->middleware('auth', ['only' => ['destroy', 'store', 'update']]); if (Auth::check() === true && Auth::user()->isAdmin() !== true) { abort(403); } }
/** * Enqueue assets. */ public function enqueueScripts() { if (current_action() === 'login_enqueue_scripts') { $root = $this->container->getRoot(); $root->get('services.js_manager')->load(); $root->get('controller.front')->enqueueScripts(); $root->get('services.css_manager')->load(); $root->get('controller.front')->enqueueStyles(); } wp_enqueue_script($this->container->getSlug() . '_loginButton'); }
public function __construct() { parent::__construct(); view()->share('current_action', 'forum-forum-covers-' . current_action()); $this->middleware('auth', ['only' => ['destroy', 'store', 'update']]); $this->middleware(function ($request, $next) { if (Auth::check() && !Auth::user()->isAdmin()) { abort(403); } return $next($request); }); }
public function update_tax_children_option($taxonomy_input = false) { global $wpml_language_resolution, $wp_taxonomies; $language_codes = $wpml_language_resolution->get_active_language_codes(); $language_codes[] = 'all'; $taxonomy = str_replace(array('create_', 'edit_'), '', current_action()); $taxonomy = isset($wp_taxonomies[$taxonomy]) ? $taxonomy : $taxonomy_input; foreach ($language_codes as $lang) { $tax_children = $this->get_tax_hier_array($taxonomy, $lang); $option_key = "{$taxonomy}_children_{$lang}"; update_option($option_key, $tax_children); } }
/** * Adds tabs to screen on 'load-' . $tab['page'] * * Loops through all tabs and adds them on the appropriate screen */ static function add_tab_to_screen() { $id = substr(current_action(), 5); $tabs = self::$tabs_by_page[$id]; foreach ((array) $tabs as $tab) { // if post type arg is set, check the post type - if not same return if (isset($tab['args']['post_type'])) { if (!self::is_current_post_type($tab)) { continue; } } $callback = !empty($tab['args']['callback']) ? $tab['args']['callback'] : array(__CLASS__, 'echo_tab_html'); get_current_screen()->add_help_tab(array('id' => $tab['id'], 'title' => $tab['title'], 'callback' => $callback)); } }
/** * Clear the authentication cookies. * * @param array|string $cookie The current authentication cookie. */ public static function purge_browser_cookie($cookie) { // Remove the action to prevent recursion with some plugins (notably s2member) remove_action(current_action(), array(__CLASS__, __FUNCTION__)); /* * Sometimes the cookie is empty because WordPress uses multiple types of auth cookies. * When one of the cookies is empty, we don't want to purge the cookies because other * cookies may have us legitimately logged in *and* empty cookies (e.g., unset) aren't * doing the cache-busting that prompts us to want to purge. */ if (empty($cookie)) { return; } wp_clear_auth_cookie(); }
public function request() { $data = $_POST; if (!isset($data['nonce'])) { wp_send_json_error(__('Missing nonce.', 'customizer-definitely')); } if (!check_ajax_referer('wpcd-customize-preprocess', 'nonce', false)) { wp_send_json_error(__('Invalid nonce.', 'customizer-definitely')); } $method_name = str_replace('-', '_', str_replace('wp_ajax_wpcd-', '', current_action())); if (!method_exists($this, $method_name)) { wp_send_json_error(__('Invalid action.', 'customizer-definitely')); } $response = $this->{$method_name}($data); if (is_wp_error($response)) { wp_send_json_error($response->get_error_message()); } wp_send_json_success($response); }
function popmake_render_popup_theme_styles() { if (current_action() == 'wp_head' && popmake_get_option('disable_popup_theme_styles', false) || current_action() == 'admin_head' && !popmake_is_admin_popup_page()) { return; } $styles = get_transient('popmake_theme_styles'); if (!$styles) { $styles = ''; foreach (popmake_get_all_popup_themes() as $theme) { $theme_styles = popmake_render_theme_styles($theme->ID); if ($theme_styles != '') { $styles .= "/* Popup Theme " . $theme->ID . ": " . $theme->post_title . " */\r\n"; $styles .= $theme_styles; } } set_transient('popmake_theme_styles', $styles, 7 * DAY_IN_SECONDS); } // echo '<style id="popup-maker-themes" type="text/css">' . $styles . '</style>'; }
/** * Trashes all related posts. * * @since 3.0.0 * @wp-hook wp_trash_post * * @param int $post_id Post ID. * * @return int The number of related posts trashed. */ public function trash_related_posts($post_id) { if (!$this->setting_repository->get($post_id)) { return 0; } $current_site_id = get_current_blog_id(); $related_posts = $this->content_relations->get_relations($current_site_id, $post_id, 'post'); unset($related_posts[$current_site_id]); if (!$related_posts) { return 0; } $trashed_post = 0; // Temporarily remove the function to avoid recursion. $action = current_action(); remove_action($action, [$this, __FUNCTION__]); array_walk($related_posts, function ($post_id, $site_id) use(&$trashed_post) { switch_to_blog($site_id); $trashed_post += (bool) wp_trash_post($post_id); restore_current_blog(); }); // Add the function back again. add_action($action, [$this, __FUNCTION__]); return $trashed_post; }
/** * Switches the theme. * * Accepts one argument: $stylesheet of the theme. It also accepts an additional function signature * of two arguments: $template then $stylesheet. This is for backwards compatibility. * * @since 2.5.0 * * @global array $wp_theme_directories * @global WP_Customize_Manager $wp_customize * @global array $sidebars_widgets * * @param string $stylesheet Stylesheet name */ function switch_theme($stylesheet) { global $wp_theme_directories, $wp_customize, $sidebars_widgets; $_sidebars_widgets = null; if ('wp_ajax_customize_save' === current_action()) { $_sidebars_widgets = $wp_customize->post_value($wp_customize->get_setting('old_sidebars_widgets_data')); } elseif (is_array($sidebars_widgets)) { $_sidebars_widgets = $sidebars_widgets; } if (is_array($_sidebars_widgets)) { set_theme_mod('sidebars_widgets', array('time' => time(), 'data' => $_sidebars_widgets)); } $nav_menu_locations = get_theme_mod('nav_menu_locations'); if (func_num_args() > 1) { $stylesheet = func_get_arg(1); } $old_theme = wp_get_theme(); $new_theme = wp_get_theme($stylesheet); $template = $new_theme->get_template(); update_option('template', $template); update_option('stylesheet', $stylesheet); if (count($wp_theme_directories) > 1) { update_option('template_root', get_raw_theme_root($template, true)); update_option('stylesheet_root', get_raw_theme_root($stylesheet, true)); } else { delete_option('template_root'); delete_option('stylesheet_root'); } $new_name = $new_theme->get('Name'); update_option('current_theme', $new_name); // Migrate from the old mods_{name} option to theme_mods_{slug}. if (is_admin() && false === get_option('theme_mods_' . $stylesheet)) { $default_theme_mods = (array) get_option('mods_' . $new_name); if (!empty($nav_menu_locations) && empty($default_theme_mods['nav_menu_locations'])) { $default_theme_mods['nav_menu_locations'] = $nav_menu_locations; } add_option("theme_mods_{$stylesheet}", $default_theme_mods); } else { /* * Since retrieve_widgets() is called when initializing a theme in the Customizer, * we need to to remove the theme mods to avoid overwriting changes made via * the Customizer when accessing wp-admin/widgets.php. */ if ('wp_ajax_customize_save' === current_action()) { remove_theme_mod('sidebars_widgets'); } if (!empty($nav_menu_locations)) { $nav_mods = get_theme_mod('nav_menu_locations'); if (empty($nav_mods)) { set_theme_mod('nav_menu_locations', $nav_menu_locations); } } } update_option('theme_switched', $old_theme->get_stylesheet()); /** * Fires after the theme is switched. * * @since 1.5.0 * * @param string $new_name Name of the new theme. * @param WP_Theme $new_theme WP_Theme instance of the new theme. */ do_action('switch_theme', $new_name, $new_theme); }
/** * Delete or trash a post connected to an entry * * @since 1.17 * * @param int $entry_id ID of entry being deleted/trashed * @param array $entry Array of the entry being deleted/trashed */ public function process_connected_posts($entry_id = 0, $entry = array()) { // The entry had no connected post if (empty($entry['post_id'])) { return; } /** * @filter `gravityview/delete-entry/delete-connected-post` Should posts connected to an entry be deleted when the entry is deleted? * @since 1.17 * @param boolean $delete_post If trashing an entry, trash the post. If deleting an entry, delete the post. Default: true */ $delete_post = apply_filters('gravityview/delete-entry/delete-connected-post', true); if (false === $delete_post) { return; } $action = current_action(); if ('gravityview/delete-entry/deleted' === $action) { $result = wp_delete_post($entry['post_id'], true); } else { $result = wp_trash_post($entry['post_id']); } if (false === $result) { do_action('gravityview_log_error', __METHOD__ . ' (called by ' . $action . '): Error processing the Post connected to the entry.', $entry); } else { do_action('gravityview_log_debug', __METHOD__ . ' (called by ' . $action . '): Successfully processed Post connected to the entry.', $entry); } }
/** * Collect cookie authentication status. * * Collects errors from {@see wp_validate_auth_cookie} for * use by {@see json_cookie_check_errors}. * * @see current_action() * @global mixed $wp_json_auth_cookie */ function json_cookie_collect_status() { global $wp_json_auth_cookie; $status_type = current_action(); if ($status_type !== 'auth_cookie_valid') { $wp_json_auth_cookie = substr($status_type, 12); return; } $wp_json_auth_cookie = true; }
/** * Set up CSRF Protection and Authentication Beta filters. * * @return void */ public function __construct() { view()->share('current_section', $this->section); view()->share('current_action', ($this->actionPrefix ?? '') . current_action()); }
public function __construct() { parent::__construct(); view()->share('current_action', 'forum-topics-' . current_action()); $this->middleware('auth', ['only' => ['create', 'preview', 'reply', 'store', 'lock']]); }
/** * Capture the actions fired when calling WP_Customize_Manager::set_post_value(). * * @see Tests_WP_Customize_Manager::test_set_post_value() */ function capture_customize_post_value_set_actions() { $action = current_action(); $args = func_get_args(); $this->captured_customize_post_value_set_actions[] = compact( 'action', 'args' ); }
/** * Handle actions from the Edit Order order actions select box * * @since 3.0 * @param object $order WC_Order object */ public function process_order_meta_box_actions($order) { $order = new WC_FreshBooks_Order($order->id); switch (current_action()) { case 'woocommerce_order_action_wc_freshbooks_create_and_send_invoice': $order->create_invoice(); break; case 'woocommerce_order_action_wc_freshbooks_create_draft_invoice': $order->create_invoice(false); break; case 'woocommerce_order_action_wc_freshbooks_send_invoice': $order->send_invoice(); break; case 'woocommerce_order_action_wc_freshbooks_apply_invoice_payment': $order->apply_invoice_payment(); break; case 'woocommerce_order_action_wc_freshbooks_update_invoice': $order->update_invoice_from_order(); break; default: return; } }
/** * Disable to mange other vendor options * * @author Andrea Grillo <*****@*****.**> * @since 1.6 * @return void */ public function disabled_manage_other_comments() { $vendor = yith_get_vendor('current', 'user'); if ('load-comment.php' == current_action() && $vendor->is_valid() && $vendor->has_limited_access() && !empty($_GET['action']) && 'editcomment' == $_GET['action']) { $comment = get_comment($_GET['c']); if (!in_array($comment->comment_post_ID, $vendor->get_products())) { wp_die(sprintf(__('You do not have permission to edit this review. %1$sClick here to view and edit your product reviews%2$s.', 'yith_wc_product_vendors'), '<a href="' . esc_url('edit-comments.php') . '">', '</a>')); } } }
/** * Collects cookie authentication status. * * Collects errors from wp_validate_auth_cookie for use by rest_cookie_check_errors. * * @since 4.4.0 * * @see current_action() * @global mixed $wp_rest_auth_cookie */ function rest_cookie_collect_status() { global $wp_rest_auth_cookie; $status_type = current_action(); if ('auth_cookie_valid' !== $status_type) { $wp_rest_auth_cookie = substr($status_type, 12); return; } $wp_rest_auth_cookie = true; }
/** * Make sure current_action() behaves as current_filter() * * @ticket 14994 */ function test_current_action() { global $wp_current_filter; $wp_current_filter[] = 'first'; $wp_current_filter[] = 'second'; // Let's say a second action was invoked. $this->assertEquals('second', current_action()); }
/** * Hook handler for 'edit_form_top', 'edit_form_after_title'. 'edit_form_after_editor' and 'edit_form_advanced'. * * Displayed the post_type's default form based on the value of post_type_object->default_form that can be set * as an argument to register_post_type. Valid values for default form include: * * 'top', 'after_title', 'after_editor', 'advanced', or 'custom_fields' * * @todo Explain how to handle custom metaboxes once we figure out how we'll handle them. * * @param WP_Post $post * * @internal * */ static function _edit_post_form($post) { $post_type = $post->post_type; $object_type = wp_get_post_object_type($post_type); $current_form = preg_replace('#^edit_form_(.*)$#', '$1', current_action()); if ($current_form == get_post_type_object($post_type)->default_form) { if (!self::form_registered($current_form, $object_type)) { self::register_form($current_form, $object_type); } $form = self::get_form($current_form, $object_type); $form->set_storage_object($post); $form->the_form(); } }
/** * General action callback for any kind of request. * * It makes the necessary security nonce checks and sends the response in the * appropriate way. * * @since 1.0.0 * @access protected * * @param string $mode Either 'admin', 'ajax' or 'cron'. Default 'admin'. */ protected function handle_request($mode = 'admin') { $ajax = false; $prefix = 'admin_action_wpenc_'; $args = $_REQUEST; switch ($mode) { case 'cron': $prefix = 'wp_encrypt_'; $args = array('context' => is_multisite() ? 'network' : 'site', '_wpnonce' => wp_create_nonce('wp_encrypt_action')); break; case 'ajax': $prefix = 'wp_ajax_wpenc_'; $ajax = true; break; } $network_wide = $this->is_network_request($args); $action = str_replace($prefix, '', current_action()); $valid = $this->check_request($action, $mode, $args); if (is_wp_error($valid)) { if ('cron' === $mode) { return; } $this->handle_error($valid, $ajax, $network_wide); } $response = call_user_func(array($this, $action), $args, $network_wide); if (is_wp_error($response)) { if ('cron' === $mode) { return; } $this->handle_error($response, $ajax, $network_wide); } if ('cron' === $mode) { return; } $this->handle_success($response, $ajax, $network_wide); }
/** * Helper to check if the webhook should be delivered, as some hooks * (like `wp_trash_post`) will fire for every post type, not just ours. * * @since 2.2 * @param mixed $arg first hook argument * @return bool true if webhook should be delivered, false otherwise */ private function should_deliver($arg) { // only active webhooks can be delivered if ('active' != $this->get_status()) { return false; } $current_action = current_action(); // only deliver deleted event for coupons, orders, and products if ('delete_post' == $current_action && !in_array($GLOBALS['post_type'], array('shop_coupon', 'shop_order', 'product'))) { return false; } elseif ('delete_user' == $current_action) { $user = get_userdata(absint($arg)); // only deliver deleted customer event for users with customer role if (!$user || !in_array('customer', (array) $user->roles)) { return false; } // check if the custom order type has chosen to exclude order webhooks from triggering along with its own webhooks. } elseif ('order' == $this->get_resource() && !in_array(get_post_type(absint($arg)), wc_get_order_types('order-webhooks'))) { return false; } elseif (0 === strpos($current_action, 'woocommerce_process_shop')) { // the `woocommerce_process_shop_*` hook fires for both updates // and creation so check the post creation date to determine the actual event $resource = get_post(absint($arg)); // a resource is considered created when the hook is executed within 10 seconds of the post creation date $resource_created = time() - 10 <= strtotime($resource->post_date_gmt); if ('created' == $this->get_event() && !$resource_created) { return false; } elseif ('updated' == $this->get_event() && $resource_created) { return false; } } return true; }
public static function scrub() { $data = Scrubber::get_data(); // Find out which action we're doing $hook = current_action(); // Bail if we don't have any transients to clear for this action if (!property_exists($data, $hook)) { return; } foreach ($data->{$hook} as $key) { delete_transient($key); Scrubber::unschedule_deletion_on_hook($key, $hook); } }
/** * Save extra taxonomy fields for product vendors taxonomy * * @author Andrea Grillo <*****@*****.**> * * @param $vendor_id string The vendor id * * @return void * @since 1.0 */ public function save_taxonomy_fields($vendor_id = 0) { if (!isset($_POST['yith_vendor_data'])) { return; } $is_new = strpos(current_action(), 'created_') !== false; // if not is set $vendor_id check if there is the update_vendor_id field inside the $_POST array if (empty($vendor_id) && isset($_POST['update_vendor_id'])) { $vendor_id = $_POST['update_vendor_id']; } $vendor = yith_get_vendor($vendor_id); if (!$vendor->is_valid()) { return; } $post_value = $_POST['yith_vendor_data']; $usermeta_owner = YITH_Vendors()->get_user_meta_owner(); $usermeta_admin = YITH_Vendors()->get_user_meta_key(); if (!$vendor->has_limited_access()) { foreach (apply_filters('yith_wpv_save_checkboxes', array('enable_selling'), $vendor->has_limited_access()) as $key) { !isset($post_value[$key]) && ($post_value[$key] = 'no'); } } else { foreach (apply_filters('yith_wpv_save_checkboxes', array(), $vendor->has_limited_access()) as $key) { !isset($post_value[$key]) && ($post_value[$key] = 'no'); } } // set values foreach ($post_value as $key => $value) { if ($key == 'description') { $vendor->{$key} = $value; } else { $vendor->{$key} = !is_array($value) ? wc_clean($value) : $value; } } // add vendor registrantion date if ($is_new) { $vendor->registration_date = current_time('mysql'); $vendor->registration_date_gmt = current_time('mysql', 1); } // Get current vendor admins and owner $admins = $vendor->get_admins(); $owner = $vendor->get_owner(); // Remove all current admins (user meta) foreach ($admins as $user_id) { $user = get_user_by('id', $user_id); delete_user_meta($user_id, $usermeta_admin); $user->remove_role(YITH_Vendors()->get_role_name()); $user->add_role('customer'); } // Remove current owner and update it if (!empty($post_value['owner']) && $owner != $post_value['owner']) { delete_user_meta($owner, $usermeta_owner); update_user_meta(intval($post_value['owner']), $usermeta_owner, $vendor->id); $owner = intval($post_value['owner']); } elseif (empty($post_value['owner']) && 'admin_action_yith_admin_save_fields' != current_action() && $vendor->is_super_user()) { delete_user_meta($owner, $usermeta_owner); delete_user_meta($owner, $usermeta_admin); $user = get_user_by('id', $user_id); if ($user instanceof WP_User) { $user->remove_role(YITH_Vendors()->get_role_name()); $user->add_role('customer'); } $owner = ''; } //Add Vendor Owner if (!isset($post_value['admins'])) { $post_value['admins'] = array($owner); } else { $temp_admins = $post_value['admins']; $post_value['admins'] = explode(',', $temp_admins); if (!empty($owner)) { $post_value['admins'][] = $owner; } } // Only add selected admins if (!empty($post_value['admins'])) { foreach ($post_value['admins'] as $user_id) { update_user_meta($user_id, $usermeta_admin, $vendor->id); $user = get_user_by('id', $user_id); if ($user instanceof WP_User) { $user->add_role(YITH_Vendors()->get_role_name()); $user->remove_role('customer'); } } } do_action('yith_wpv_after_save_taxonomy', $vendor, $post_value); if ('admin_action_yith_admin_save_fields' == current_action()) { wp_redirect(esc_url_raw(add_query_arg(array('page' => $_POST['page'], 'tab' => $_POST['tab'])))); } }
/** * Helper to check if the webhook should be delivered, as some hooks. * (like `wp_trash_post`) will fire for every post type, not just ours. * * @since 2.2 * @param mixed $arg first hook argument * @return bool true if webhook should be delivered, false otherwise */ private function should_deliver($arg) { $should_deliver = true; $current_action = current_action(); // only active webhooks can be delivered if ('active' != $this->get_status()) { $should_deliver = false; // only deliver deleted event for coupons, orders, and products } elseif ('delete_post' === $current_action && !in_array($GLOBALS['post_type'], array('shop_coupon', 'shop_order', 'product'))) { $should_deliver = false; } elseif ('delete_user' == $current_action) { $user = get_userdata(absint($arg)); // only deliver deleted customer event for users with customer role if (!$user || !in_array('customer', (array) $user->roles)) { $should_deliver = false; } // check if the custom order type has chosen to exclude order webhooks from triggering along with its own webhooks. } elseif ('order' == $this->get_resource() && !in_array(get_post_type(absint($arg)), wc_get_order_types('order-webhooks'))) { $should_deliver = false; } elseif (0 === strpos($current_action, 'woocommerce_process_shop') || 0 === strpos($current_action, 'woocommerce_process_product')) { // the `woocommerce_process_shop_*` and `woocommerce_process_product_*` hooks // fire for create and update of products and orders, so check the post // creation date to determine the actual event $resource = get_post(absint($arg)); // a resource is considered created when the hook is executed within 10 seconds of the post creation date $resource_created = time() - 10 <= strtotime($resource->post_date_gmt); if ('created' == $this->get_event() && !$resource_created) { $should_deliver = false; } elseif ('updated' == $this->get_event() && $resource_created) { $should_deliver = false; } } /* * Let other plugins intercept deliver for some messages queue like rabbit/zeromq */ return apply_filters('woocommerce_webhook_should_deliver', $should_deliver, $this, $arg); }