WordPress.org

Ready to get started?Download WordPress

Forums

How to execute a plugin script when a http request is adressed ? (1 post)

  1. ben.IT
    Member
    Posted 1 year ago #

    Hi,
    I wrote a plugin which performs some notification tasks.This works fine.
    Now, I want to execute the main plugin script when a HTTP request is adressed.
    That's here I am a little confused :

    My plugin source code is located in the classical WP plugin directory :
    /wp-content/plugins/my-plugin

    And here is the source of the main script that I want to be executed when an http request is adressed :

    <?php
    require_once('../wp-load.php');
    require_once(ABSPATH."wp-content/plugins/my-plugin/classes/Model.class.php") ;
    require_once(ABSPATH."wp-content/plugins/my-plugin/classes/MailNotifier.class.php") ;
    
    $mailNotif= new MailNotifier('myadress@foo.bar');
    $mailNotif->sendMailToRecipient() ;
    ?>

    Currently, this script is located in : WordPressRoot/script/main.php this works, but I would like to remove it from the WP core files and only get files in my plugin directory.
    I actually execute this script addressing the following http request: http://mydomain.com/script/main.php

    How should I do this :
    Shall I wrote a webservice in wordpress (I am not really familiar with this) ?
    Shall I use a redirection rule in wordpress ?

    What is the best way to do this proper ?
    Thanks, greetings ben.

Topic Closed

This topic has been closed to new replies.

About this Topic