How would go about if I just want a temporary function?

How would go about if I just want a temporary function? (It’s a converter just for converting Access to WordPress tables). I want to execute several times so therefore I want it automated, but I don’t know how to execute the function after adding the filter in add_action(). After I’m done converting, I will delete the function.

I want to do something like http://url/index.php?convert

Read More
function addcoursecategoriesfromaccess() {
    //code for converting the table
}
add_action('convert','addcoursecategoriesfromaccess');

//If I type http://url/index.php?convert then I want the addcoursecategoriesfromaccess()  to execute
if ($_REQUEST['GET'] == 'convert') {
    do_action('convert');
}

I guess I’m missing something very simple, but as a newbie in WP-programming I hope you can help me out 🙂 I’ve the code inside functions.php in the theme.

Related posts

2 comments

  1. Use e.g. the init hook instead. For instance;:

    if (isset($_GET['convert'])) add_action('init', 'yourfunction');
    

    (Come up with a better check, though. ?convert could mean anything. And secure it by checking for user permissions, that it hasn’t already run, etc.)

  2. Instead you could hook into init

    add_action( 'init', 'addcoursecategoriesfromaccess' );
    function addcoursecategoriesfromaccess() {
         if ( ! filter_has_var( INPUT_GET, 'convert' )
             return;
    
         // code here
    }
    

    Then when you want to run it, just go to the URL as you wrote ( {url}/?convert=1 ) and then the addcoursecategoriesfromaccess will run.

Comments are closed.