I am using a function that redirects the user to a custom page, rather than wp-login in the event of errors. In my case I am using the Http Referer function to send the user back to the same page because I have the login form in a modal. How can I execute a function on the redirected page, so that the page automatically opens the modal? This is the code for the redirect in the event of an error: …
What is the right action to invoke before a custom post type is getting edited in dashboard and contains the argument the post id? The url /wp-admin/post.php?post=282&action=edit&classic-editor here is what I try $userId = get_current_user_id(); $affiliate = get_field('field_627ff399b5ef6', 'user_' . $userId); $this->currentAffiliate = $affiliate; $subPages = get_children([ 'post_parent' => $affiliate[0]->ID, 'post_type' => 'affiliate', ]); $pageIds = collect($subPages)->pluck('ID')->push($affiliate[0]->ID)->toArray(); if edit page ID is not in $pageIds redirect to the not allowed screen
I need to provide a list of all options set via plugins etc to remote calls. There is a plugin WP API Options but it hardly does the job. There are two possible ways (that I know of) to get a list of all options set in the blog/site: Use $wpdb to run a query like so: $option_names = $wpdb->get_col( "SELECT DISTINCT option_name FROM $wpdb->options WHERE option_name NOT LIKE '_transient_%'" ); Use wp_load_alloptions() Which one of these two would be …
I am having some issues determining the solution to this problem below. The website was sent to our team to fix. Turned on error reporting in wp-config.php: define('WP_DEBUG', true); WordPress version: 5.3.2PHP version: 7.2 WordPress Theme: Grow Pro Fatal error: Uncaught Error: Class 'WP_Block_Styles_Registry' not found in /home/website/public_html/clientsite.com/wp-includes/script- loader.php:2902 Stack trace: #0 /home/website/public_html/clientsite.com/wp-includes/class-wp- hook.php(288): enqueue_block_styles_assets('') #1 /home/website/public_html/clientsite.com/wp-includes/class-wp- hook.php(312): WP_Hook->apply_filters(NULL, Array) #2 /home/website/public_html/clientsite.com/wp-includes/plugin.php(478): WP_Hook->do_action(Array) #3 /home/website/public_html/clientsite.com/wp-includes/script- loader.php(2856): do_action('enqueue_block_a...') #4 /home/website/public_html/clientsite.com/wp-includes/class-wp- hook.php(288): wp_common_block_scripts_and_styles('') #5 /home/website/public_html/clientsite.com/wp-includes/class-wp- hook.php(312): WP_Hook->apply_filters(NULL, Array) #6 /home/website/public_html/clientsite.com/wp-includes/plugin.php(478): WP_Hook->do_action(Array) #7 …
I can current filter the content type of the wp_mail function: add_filter( 'wp_mail_content_type', function( $content_type ) { return 'text/html'; }); And I can filter the message content add_filter( 'wp_mail', function( $args ) { $args['message'] = 'Filtered text here'; return $args; }); But how can I only do the latter conditionally? I only want to filter the message when the content type == text/plain. I'm guessing there is a super-simple solution to this, but I haven't worked it out yet.
I have the following functions: function test($post_id){ do_action('test_action',$post_id); echo $post_id; } add_action('test_action',function($post_id){ if ( $post_id == 2 ) //Stop test function execution } Using the function hooked to add_action, how to stop the execution of test() function without adding any code to test(). In the above example, if $post_id == 2 , the echo $post_id; code should not run in test().
Excuse me if something like this has been asked before. So, I'm trying to alter the query which displays the posts of a custom post type, but on the admin side, more precisely, the edit.php page. This is my code: function my_function() { global $pagenow, $typenow; if( 'edit.php' == $pagenow && 'certain-post-type' === $typenow ) { // do something } } add_action( 'admin_init', 'my_function' ); The main problem is not altering the query itself (yet!), but targeting only the edit.php …
I have a custom post type that always do math operation to its post_meta and other custom post type post_meta. For example: post-type 1 = cpt_product_order post-type 1 post_meta = cpt_pm_product_order post-type 2 = cpt_product post-type 2 post_meta = cpt_pm_product_stock There's a cpt_product with cpt_pm_product_stock = 100, frontend operation enable specific user made order by inserting new cpt_product with post_meta cpt_product_order of 10 will substract cpt_pm_product_stock to 90 100 cpt_pm_product_stock - 10 cpt_product_order = 90 cpt_pm_product_stock cancelling order will delete/trash …
I am trying to configure WordPress 5.9 to allow numeric slugs for child pages. Drawing from the 2015 answer to a similar question I took the up-to-date code of wp_unique_post_slug, removed || preg_match( "@^($wp_rewrite->pagination_base)?\d+$@", $slug ) and then added it as the following hook to my theme's functions.php. But for some reason, I just get a critical error: "Allowed memory size exhausted". What can I do to allow numeric slugs for child pages? add_filter( 'wp_unique_post_slug', function ( $slug, $post_ID, $post_status, …
By default, the product quantity is always "1" when viewing a product page. There doesn't seem an out-of-the-box option to set a different quantity value upon visit, and I don't know what hook or function to look for. Your help is appreciated.
I have a script which scrapes articles from the web and saves the url to a .txt file. I've created a custom plugin which on activation, loops through the urls and creates a draft post with the content being an embedded article. I'm using the following code in my plugin <?php register_activation_hook(__FILE__, 'my_plugin_activate'); function my_plugin_activate(){ my_plugin_install_site(); } function my_plugin_install_site(){ global $user_ID; $handle = fopen("listOfURLs.txt", "r"); if ($handle) { $count = 0; while (($line = fgets($handle)) !== false) { // process …
I have Used the function dynamic_sidebar('sidebarId') in the sidebar.php file. and all the functionality of the sidebar is Working succsessfully My Question is How To Change the Html of the sidebar widgets and add some classes in widget items To fit My Design ? Thank You in advance
Yesterday, I found out that a website I worked on as a writer (I have no admin access) had been injecting malicious Javascript code in all its pages, as described in this article by Luke Leal. According to that article, a fake Wordpress plugin musts have been installed on that website to inject the malicious code. I want to draw your attention to this section of the malicious code: // This code is defined inside a PHP class... function save_striplple_plugin() …
Is it possible to add an action hook via wp_localize_script, so I can position where I want the hook to run in HTML markup that is made in the JavaScript? So something like: $data = array ( 'ng_slicknav' => array( 'ng_slicksearch' => home_url( '/' ), 'ng_slicknav_closedsymbol' => esc_html( $options['ng_slicknav_closedsymbol'] ), 'ng_slicknav_hook' => do_action( 'myplugin_after_hook' ), ), ); // Add filter $data = apply_filters( 'ng_slicknav_slickNavVars', $data ); // Pass PHP variables to jQuery script wp_localize_script( 'slicknav-init', 'slickNavVars', $data ); wp_enqueue_script( 'slicknav-init' …
I need to restrict the button "EMPTY TRASH" and make it delete only the posts only if the logged in user is the creator. I tried to use the wp_trash_post and i need to decide in the function if i need to continue to trash or not. How do i tell WordPress NOT to empty the trash from specific posts?
I recently started writing a rest api for my plugin. I need to access some custom posts however WP_Query is returning an empty array when I'm querying the db. There is the custom post type declaration. // custom post type declaration add_action('init', 'register_plugin_custom_post_type'); function register_plugin_custom_post_type() { register_post_type('my_post_type', [ 'label' => "A name", 'StackExchange exemple', 'public' => false, 'show_in_rest' => true ]); } Rest api route registration add_action('wp_rest_init', 'my_plugin_rest_init_callback'); function my_plugin_wp_rest_callback() { register_rest_route('my-rest-route', '/endpoint', [ 'method' => 'GET', 'callback' => 'rest_api_callback', …
What I try to achieve is to have the portfolio slug as a page slug also, and when I will assign the page as a parent to another, then that page must look for a specific page's parent ID and return the correct results. If I have the same slug in portfolio and in a page and try to create a child page, then I will get an error. Example: Portfolio slug: test/rent-a-car. Page slug: test/rent-a-car. If I create a …
I'm syncing my Wordpress authentication system with an secondary/external authentication system and my site has at least two ways of resetting the password, including: Password reset email User account screen password reset There may be some third way I'm not recalling, as I've disallowed password resets thus far due to my inability to sync the systems. The crux of my question: How can I hook into the password reset prior to hashing so that I can simultaneously set the new …