Skip to content

Hooks of WP cron schedule events #9

Open

Description

@kkmuffme

Activity

  1. johnbillion commented on May 6, 2022

    @johnbillion
    Member

    Thanks for the report. How should these be documented? It's a dynamic hook added by other plugins.

  2. kkmuffme commented on May 6, 2022

    @kkmuffme
    CollaboratorAuthor

    Just normally with phpdoc for the $args I'd say

    /**
     * @param string $foo
     * @param int
     */
    wp_schedule_single_event( strtotime( '+ 2 days' ), 'my_custom_cron_hook', array( $foo, 10 ) );
    

    However, I would be 100% happy if these hooks would just be included in the actions.json without any args/docs, as I use actions.json primarily to ensure that used hooks exist (and only secondary to validate the hook types)

  3. johnbillion commented on May 6, 2022

    @johnbillion
    Member

    Ah I see what you mean. While that would be useful it would require a whole different parser to detect and extract these. PRs welcome!

  4. kkmuffme commented on May 7, 2022

    @kkmuffme
    CollaboratorAuthor

    It's easy enough with nikic PHP parser directly in enterNode function for e.g. wp_schedule_single_event: (for wp_schedule_event index is 2 instead of 1)

    if ( in_array( (string) $node->name, $event_functions, true ) ) {
    	$hook_type = 'action';
    	
    	if ( ! $origNode->args[1]->value instanceof String_ ) {
    	        return null;
            }
    
    	$hook_name = $origNode->args[1]->value->value;
    }
    

    And the way to get the phpdoc is the same as now for actions/filters.

  5. kkmuffme commented on May 19, 2022

    @kkmuffme
    CollaboratorAuthor

    Is there maybe some way I can custom add this (like a custom visitor or something I can declare when calling the hooks generator)?
    bc I realized there are some custom cases, that will call a hook callback too, I'd like to add (besides the obvious WP cron stuff and the WC action scheduler)

  6. johnbillion commented on May 19, 2022

    @johnbillion
    Member

    I'm really not sure - the parsing is handled by wp-parser-lib which is just the parsing code from the WP Parser plugin extracted into a reusable library. I've not looked into it in depth.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions