Add new users to "add new user" page on admin's dashboard

I understand there's a lot of similar questions, but all of them show how to update the wp_usermeta table in the database, whereas I want to use wp_update_user() to update a particular field (nickname <-> user_nicename) in the wp_users table. Here is my snippet, (which I have collected from other similar questions) it appends the new field to the "add new user" page, but it doesn't save the information in the database with wp_update_user(). P.S.: I also would like to …
Category: Web

Restrict editing of post type to list stored in user meta

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
Category: Web

add_action insert html

I know I am missing something simple. I am trying to use html to log to footer to learn wp. In theme functions.php: function myLog() { echo 'test'; } In theme footer within the .siteInfo div: <?php add_action( 'wpmu_new_blog', 'myLog' );?> when a new user creates a new site myLog should output html 'test'? Please help, save me many more hours of reading and trials.
Category: Web

Scheduled event won't fire

I'm trying to set up individual, one-time schedule events in a plugin. No matter what I do, I can't seem to get the events to fire. I'm using the Cron View plugin to see what's in queue, and the events are added and remove themselves totally on schedule. I never, however, receive the email I've set to send in the action's target function (simply in order to test the event, there will be more in there later). I have tested …
Category: Web

How to stop execution of a function via add_action hook?

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().
Category: Web

Create action running on trashed_post hook to modify post_meta value

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 …
Category: Web

add_action and do_action: multiple calls to same callback?

I have a setup similar to this: function get_type_data($val) { // Get the data from the DB where the ID is $val and return it. } add_action('my_hook', array($this, 'get_type_data'), 10, 1); I need to repeat this callback for several results of another callback, which I was thinking of doing like this: // Get the types first, then... foreach ($type as $val) { add_action('my_hook', array($this, 'get_type_data'), 10, 1); do_action('my_hook', $val); } But it only does the first one. I then did …
Category: Web

WordPress Reset password Strength set to medium

I have been looking for an answer for a few days digging through hooks and actions. I just cane seem to find a way to turn down the strength on the reset password page not sure if its through woo-commerce or WP I have tried the following add_filter( 'woocommerce_min_password_strength', 'reduce_woocommerce_min_strength_requirement' ); function reduce_woocommerce_min_strength_requirement( $strength ) { return 2; } add_filter( 'wc_password_strength_meter_params', 'reduce_strength_meter_settings' ); function reduce_strength_meter_settings( $data ) { return array_merge( $data, array( 'min_password_strength' => 2, 'i18n_password_hint' => 'Change Hint here' …
Category: Web

Ajax callback not work

My files is : synergyservice.php register_activation_hook( __FILE__, array( 'Synergy', 'plugin_activation' ) ); register_deactivation_hook( __FILE__, array( 'Synergy', 'plugin_deactivation' ) ); if ( is_admin() || ( defined( 'WP_CLI' ) && WP_CLI ) ) { require_once( __DIR__ . '/environments.php' ); require_once( SYNERGY__PLUGIN_DIR . 'class.synergyservices.php' ); require_once( wp_normalize_path (SYNERGY__PLUGIN_DIR . 'admin/Helpers/class.helper.php' ) ); add_action( 'init', array( 'Synergy', 'init' ) ); require_once( wp_normalize_path(SYNERGY__PLUGIN_DIR . 'admin/Classes/class.synergy-admin.php') ); add_action( 'init', array( 'Synergy_admin', 'init' ) ); } class-synergyservice.php <?php class Synergy{ private static bool $initiated = false; public …
Category: Web

Add action hook into wp_localize_script

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' …
Category: Web

admin-ajax.php calls fail if referrer is sent with 500

calling admin-ajax.php via jquery ajax calls were failing from my site but postman calls to the same url were successfull. After some looking at headers it seems that the referer being set is the difference that calls the failure (500). What would possibly cause admin-ajax.php to care about whether or not a referer is being sent and fail if it is? The error logs just say that memory is running out but why would the referer header change how much …
Category: Web

How to pass multiple parameter in add_action()

I have below code. add_action( 'admin_init', [$this, 'settings_page_registration'] ); I would like to use enqueue_assets function name inside add_action(). Should I use like below ? add_action( 'admin_init', [$this, 'settings_page_registration', 'enqueue_assets'] );
Category: Web

Hook into all password resets in Wordpress and get password before hashing?

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 …
Category: Web

Find variables available at a given hook

I'm hoping for a simple way to tell/find/echo what the available arguments are available for use at a given hook. For example — function example_function($something){ //do stuff with $something return $something; } add_action('some_hook','example_function'); In the above case, is there a quick way to tell what $something is (if there is one at all), or if there are multiple $somethings / arguments I have available to use at that point?
Category: Web

Prevent posts with certain post_meta to be edited

So I am looking at adding some custom post_meta to posts and I want those posts to not be editable, which will be some content that I am pulling in. Here is what I have: I have solved the issues when visiting the Post post_type and attempting to edit a post with a specific post_meta using this (This works great in the UI): add_filter('post_row_actions', function($actions, $post) { if (get_post_meta($post->ID, 'global_post', true)) { unset($actions['edit']); unset($actions['inline hide-if-no-js']); } return $actions; }, 10, …
Category: Web

Is there a Woocommerce hook that fires when applying a coupon but before checking if it's valid?

I want to add an item to the cart (that same item gets discounted with the coupon) upon using a coupon code (with a hook). E.g. when using the coupon code SAMPLECODE, a product is added to the cart with a $2 discount. The coupon is set up to apply a $2 discount for that product only. The problem is, that my coupon code only applies to the item that is going to be added programmatically, so it fails the …
Category: Web

WP_LIST_TABLE bulk action

I created a class extend WP_List_Table and created method for bulk actions like this : function get_bulk_actions() { $actions = array( 'synchronize' => 'Synchronize', 'delete' => 'Delete from Shareino', ); return $actions; } and another method for processing their : function process_bulk_action() { //Detect when a bulk action is being triggered... if ('delete' === $this->current_action()) { wp_die('Items deleted (or they would be if we had items to delete)!'); } } This action's display in a dropbox but when i select …
Category: Web

add_action on inherit post status

I'm trying to use the add_action() hook to run a custom function, but am struggling with the post status. I originally tried using: add_action('pending_to_publish_portfolio', 'my_function'); (portfolio being my custom post type). This didn't work, so i posted in the official Wordpress Support forum for some help. I was given the following code to get the right transition status' function bj_test($new, $old) { print_r($old . '_to_' . $new); echo '<br>'; print_r($old . '_' . $new); die(); } add_action('transition_post_status', 'bj_test', 10, 2); …
Category: Web

Displaying page content from plugin, inside exising empty WP page

Old php developer here, very.. very new to WP, so be kind. I am building my first WP Plugin. I have this in the plugin central file (the one that is /plugins/my_plugin/my_plugin.php): // Setup the admin management page function wx_admin_burger_management() { add_menu_page( 'Burger Manager', // Page title 'Burger Manager', // Menu title 'manage_options', // Capability 'admin-manage-burger', // Menu slug 'wx_burger_admin', // Callback function 'dashicons-list-view', // Menu icon '3' // Priority ); } function wx_burger_admin() { include(trailingslashit(WX_PLUGIN_PATH).'my-burger-admin.php'); } add_action('admin_menu', 'wx_admin_burger_management'); This …
Category: Web

Add custom buttons with custom actions in Edit Post screen in WordPress?

I am creating something for a client and I have a Class that I created with a Custom Post Type called 'PuSH Feeds' and when the user adds a new post and publishes it they can then click on one of two buttons that I have in the Custom Meta Box. One button is for 'Subscribe' and the other for 'Unsubscribe'. I am using the save_post action hook and testing if the $_POST global has that 'pushfeed-subscribe' or 'pushfeed-unsubscribe' and …
Category: Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.