• hi ,

    there is a plugin, written by another user.
    i have activated that plugin in WP. It works fine.

    Now i want to do some modifications and test that plugin. (dispay variables..add variables etc)
    How can i do this without running the plugin

    Say plugin file is myplugin.php
    Can i access this pluging via my site url… like http://www.mysite.com/wp-content/plugin/myplugin.php

    But then it says, it missing this and that file…

    Need your assistance. How to run this plugin

    —————Pluging code is as follows———–

    <?php
    /*
    Plugin Name: Deal Parser
    Description: Parses deal site and adds content as post
    */
    
    add_action('admin_menu', 'deal_parser_menu');
    
    function deal_parser_menu()
    {
        add_menu_page('Deal Parser', 'Deal Parser', 'manage_options', 'dealparser', 'deal_parser_page', '', 6);
    }
    
    function deal_parser_page()
    {
        ?>
        <script>
            (function ($) {
                $(document).ready(function () {
    
                    var ajaxurl = '<?php echo admin_url('admin-ajax.php'); ?>';
                    $('#runner').on('click', function () {
                        var realthis = $(this);
                        $(this).prop('disabled', true);
                        $(this).after('<img style="margin-left:20px" id="theloader" src="<?=plugins_url('deal-parser/images/ajax-loader.gif') ?>">');
    
                        $.post(
                            ajaxurl,
                            {
                                'action': 'fetch_site'
                            },
                            function (response) {
                                $('#frameholder').html(response);
                                $('#theloader').remove();
                                $(realthis).prop('disabled', false);
    
                            }
                        );
                    })
                });
            })(jQuery);
    
        </script>
    
        <br>  <br>  <br>
        <input type="submit" autocomplete="off" value="Run parser manually now" class="button" id="runner" name="">
        <div id="frameholder"></div>
    <?
    }
    
    function print_pre($val)
    {
        echo "<pre>";
        print_r($val);
        echo "</pre>";
        die();
    }
    
    add_action('wp_ajax_fetch_site', 'fetch_site');
    
    function fetch_site()
    {
    
        global $wpdb;
        echo "<br>Bot starting to run..";
        echo "<br>Going to http://www.wow.lk/deals/home.jsp ..";
    
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, 'http://www.wow.lk/deals/home.jsp');
        curl_setopt($ch, CURLOPT_USERAGENT, 'Googlebot/2.1 (http://www.googlebot.com/bot.html)');
        curl_setopt($ch, CURLOPT_REFERER, 'http://www.google.com');
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
        curl_setopt($ch, CURLOPT_COOKIESESSION, true);
        curl_setopt($ch, CURLOPT_COOKIEJAR, 'wow.txt'); //could be empty, but cause problems on some hosts
        curl_setopt($ch, CURLOPT_COOKIEFILE, 'wow.txt'); //could be empty, but cause problems on some hosts
        $answer = curl_exec($ch);
        if (curl_error($ch)) {
            echo curl_error($ch);
        }
    
        include_once('simple_html_dom.php');
    
        $html = str_get_html($answer);
    
        $ret = $html->find('.marginBotm10px a');
    
        krsort($ret);
    
        foreach ($ret as $thisdeal) {
            global $wpdb;
            echo "<br>Going to http://www.wow.lk" . $thisdeal->attr['href'] . " ..";
            curl_setopt($ch, CURLOPT_URL, "http://www.wow.lk" . $thisdeal->attr['href']);
            $answer = curl_exec($ch);
    
            $html2 = str_get_html($answer);
    
            $ret2 = $html2->find('h1.marginBotm10px', 0);
    
            /*
            $check = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_title = '" . trim($ret2->innertext) . "' and post_status='published'");
    
            print_pre(trim($ret2->innertext));
            if ($check) {
                echo "<br> The deal " . trim($ret2->innertext) . ' already exists, deal updated';
                continue;
            }
    
            */
            $title = trim($ret2->innertext);
            if (get_page_by_title($title, 'OBJECT', 'seller')) :
    
                echo "<br> The deal " . trim($ret2->innertext) . ' already exists, deal updated';
    
                continue;
    
            endif;
    
    		 echo "<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>";
    			 echo "**************************************************";
    
            $ret3 = $html2->find('.dealblock_content_info_image', 0);
    
            $imageurl = $ret3->attr['src'];
            $upload_dir = wp_upload_dir();
            $image_data = file_get_contents($imageurl);
            $filename = basename($imageurl);
            $pieces = explode('.', $filename);
    
            $filenamenew = $pieces[0] . time();
            $filename = $filenamenew . "." . $pieces[1];
    
            if (wp_mkdir_p($upload_dir['path']))
                $file = $upload_dir['path'] . '/' . $filename;
            else
                $file = $upload_dir['basedir'] . '/' . $filename;
            file_put_contents($file, $image_data);
    
            $fileurl = str_replace("/home/zerandib/public_html/samplesite/", "http://ustradeads.com/samplesite/", $file);
    
            $ret4 = $html2->find('#wow_deal_bigtextarea', 0);
            $ret5 = $html2->find('#wow_deal_bigtextarea', 1);
    
            $ret6 = $html2->find('#wow_deal_validity', 0)->find('p', 0)->innertext;
    
            $ret6 = str_replace('of ','',$ret6);
            $piecesdate = explode("to", trim($ret6));
    
            $dealstart = strtotime(trim($piecesdate[0]));
    
            if($dealstart > time())
            {
                $dealstart = time();
            }
            if(!is_int($dealstart)) print_pre($dealstart);
            $dealend = strtotime(str_replace('.', '', trim($piecesdate[1])));
    
            $our_price = str_replace(',','',str_replace('Rs ','',trim($html2->find('.dealblock_price_to',0)->innertext)));
    
            $current_price = str_replace(',','',str_replace('Rs ','',trim($html2->find('.dealblock_price_from',0)->innertext)));
    
    		echo "************";
    		echo "<br/>";
    		echo $our_price;
    		echo "************";
    		echo $current_price;
    		echo "<br/>";
    		echo "************";
    
    		print_pre("**************************");
    		print_pre($our_price);
    		print_pre("**************************");
    		print_pre($current_price);
    
            $sold_count =$html2->find('#sold_count', 0)->innertext;
            $my_post = array(
                'post_title' => trim($ret2->innertext),
                'post_content' => '<div class="dealpage_header">
    <h3><a href="' . $fileurl . '"><img class="alignnone  wp-image-9" src="' . $fileurl . '" alt="2"/></a></h3>
    <a target="_blank" href="http://www.wow.lk' . $thisdeal->attr['href'] . '"><button>Get This Deal</button></a>
    <h3>Deal Terms & Conditions</h3>
    </div>
    <div id="wow_deal_bigtextarea" class="alpha omega squre_border marginTB10px">
    ' . $ret4->innertext . '
    </div>
    <div class="dealpage_header">
    <h3>About Deal</h3>
    </div>
    <div id="wow_deal_bigtextarea" class="alpha omega squre_border margintop10px marginBotm30px">
    ' . $ret5->innertext . '
    
    </div>',
                'post_status' => 'publish',
                'post_author' => 1,
                'post_category' => array(8, 39),
                'post_type' => 'seller'
            );
    
            $post_ID = wp_insert_post($my_post);
            $post_url = get_the_permalink($post_ID);
    
            $wpdb->insert("wp_postmeta", array(
                "post_id" => $post_ID,
                "meta_key" => "coupon_start_date_time",
                "meta_value" => $dealstart
            ));
    
            $wpdb->insert("wp_postmeta", array(
                    "post_id" => $post_ID,
                    "meta_key" => "coupon_end_date_time",
                    "meta_value" => $dealend
                ));
    
            $wpdb->insert("wp_postmeta", array(
                "post_id" => $post_ID,
                "meta_key" => "our_price",
                "meta_value" => $our_price
            ));
    
            $wpdb->insert("wp_postmeta", array(
                "post_id" => $post_ID,
                "meta_key" => "current_price",
                "meta_value" => $current_price
            ));
    
            $wpdb->insert("wp_postmeta", array(
                "post_id" => $post_ID,
                "meta_key" => "file_name",
                "meta_value" => $fileurl
            ));
            $wpdb->insert("wp_postmeta", array(
                "post_id" => $post_ID,
                "meta_key" => "status",
                "meta_value" => 1
            ));
    
       echo "<br> Deal with title : " . trim($ret2->innertext) . " added successfully. View post : <a href='" . $post_url . "' target='_blank'>" . $post_url . "</a>";
    
    }
    
    }
    
    ?>
Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator t-p

    (@t-p)

    one way would be to make a test site (separate from your production site). And use this test site to test all your mods.

    Yeah – You’re going to want to set up a local wordpress site. You don’t run the plugin by accessing the plugin files directly. You activate the plugin from the wordpress dashboard, which tells WP to load your plugin’s actions and filters and custom functions in the initialization of the request. Then, with your plugin’s functions loaded, you fix bugs, add features by editing the plugin files, then accessing the WP install to see if things are working properly. This enviroment should be local, so you can get quick feedback when you make a change. Development version needs to be seperate, because part of the process is breaking, and fixing the site. When there’s an error in your plugin files, the whole site is inaccessible – fine for a local version – not so fine for a live site.

    Thread Starter zerandib1

    (@zerandib1)

    in the above script why these things are not working?

    echo “************”;
    echo “
    “;
    echo $our_price;
    echo “************”;
    echo $current_price;
    echo “
    “;
    echo “************”;

    This is not displaying in the output!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘how to test a wp plugin’ is closed to new replies.