WordPress environment not loading properly

please help me with this i’ve been working on it for 2. I am sorry if the title isn’t the exact explanation of the problem but i just can’t figure out how to handle this problem.
I created a php plugin but the php file isn’t able to call any type of wordpress function example – (add_action).
at first it was giving me an error saying function undefined.
After giving giving it the location of the wp-load.php file it stoped giving me the error but it still isn’t loading anything called with add_action.
What do you think is causing this problem.

<?php 
   $parse_uri = explode( 'wp-content', $_SERVER['SCRIPT_FILENAME'] );
   require_once( $parse_uri[0] . 'wp-load.php' );
   add_action('init','addText');
   function addText(){
     echo "hello world";
   }
?>

Also i am loading this from the tinymce editor.
This is the tinymce button code it’s only job is to load the php file.
I know that i am not calling ajax in the correct way but this is the only way i can call it because it is directly loaded from my javascript file.

(function() {
    tinymce.PluginManager.add('ImageSlider', function( editor, url ) {
function customfunction() {
    jQuery(document).ready( function($) {
        var dir1 = "../wp-content/plugins/Midnight Image-Slider/MDslider.php";
        $.ajax({
            type:"POST",
            url: dir1,
            success: function(data) {
                $('.mce-window-body').append(data);
            }
        })
    })
}
editor.addButton( 'ImageSlider', {
    title: 'My test button',
    image: url + '/lion.jpg',
    onclick: function(){
        editor.windowManager.open({
            title: 'Image slider',
            width:800,
            height:450,
            body:[
                customfunction()                
            ],
            onSubmit: function(e) {


            }
        })
    }
});
});
})(); 

Answer

Attribution
Source : Link , Question Author : iani garthalski , Answer Author : Community

Leave a Comment