Forum Replies Created

Viewing 15 replies - 1 through 15 (of 21 total)
  • Thread Starter nobody123

    (@nobody123)

    @snaacks I have checked my spam folders or junk, but I still not receive any email from wordpress except your replying email.

    • This reply was modified 2 years, 2 months ago by nobody123.
    Thread Starter nobody123

    (@nobody123)

    @rynald0s My gmail didn’t received any mail

    Thread Starter nobody123

    (@nobody123)

    If I downloaded and installed manually, it displayed error, Plugin could not be activated because it triggered a fatal error., when I activated it.

    Thread Starter nobody123

    (@nobody123)

    @sebastienserre Is your mean letting the code init not callback again by if condition?
    If it is what I say, how does write the condition of if?

    @bcworkz Thanks for your suggestion.
    But it becomes to produce three posts after reload every times…

    @weboccults Thank you very much!!
    It work!!

    Thanks for everybody answer!!!

    Thread Starter nobody123

    (@nobody123)

    I understand the reason about adding too much posts using init.
    But I don’t know why do I add some checks at start of the function.
    Dose it help us solve problem?
    why?
    and how to do specifically?
    do you have try it?
    Or do you have another suggestion for adding new post using hook or any way?

    Thread Starter nobody123

    (@nobody123)

    Thank for your answer, but this problem still wasn’t solve after I modified my code.
    add_action('init', 'example_function');->add_action('plugins_loaded', 'example_function');

    First time reloading, adding a new post.
    Second time reloading, adding another 3 new posts.
    Third time reloading, adding 4 new posts……

    • This reply was modified 2 years, 5 months ago by nobody123.
    Thread Starter nobody123

    (@nobody123)

    Cool!!!
    It work!!!
    Thank you very very very much!

    Thread Starter nobody123

    (@nobody123)

    Thank for your advise, but I got error after I move my code.
    The error:
    Fatal error: Uncaught Error: Class 'Test_one' not found in D:\Appserv\Apache24\htdocs\php7.4\wordpress\wp-content\plugins\crawler\crawler.php:160 Stack trace: #0 D:\Appserv\Apache24\htdocs\php7.4\wordpress\wp-includes\shortcodes.php(356): Test->shortcode_value('', '', 'current_year') #1 [internal function]: do_shortcode_tag(Array) #2 D:\Appserv\Apache24\htdocs\php7.4\wordpress\wp-includes\shortcodes.php(228): preg_replace_callback('/\\[(\\[?)(curren...', 'do_shortcode_ta...', '\n<p>123456789</...') #3 D:\Appserv\Apache24\htdocs\php7.4\wordpress\wp-includes\class-wp-hook.php(303): do_shortcode('\n<p>123456789</...') #4 D:\Appserv\Apache24\htdocs\php7.4\wordpress\wp-includes\plugin.php(189): WP_Hook->apply_filters('\n<p>123456789</...', Array) #5 D:\Appserv\Apache24\htdocs\php7.4\wordpress\wp-includes\post-template.php(253): apply_filters('the_content', '<!-- wp:paragra...') #6 D:\Appserv\Apache24\htdocs\php7.4\wordpress\wp-content\themes\twentytwentyone_test\template-parts\content\content-single.php(23): the_content()

    The code1 (moving tojs2php_register()):

    function js2php_register(){
            require_once plugin_dir_url(__FILE__) . 'src/ming_crawler.php';
            add_action( 'wp_ajax_crawler_info', array($this, 'get_info') );
            add_action( 'wp_ajax_nopriv_crawler_info', array($this, 'get_info') );
            add_shortcode( 'current_year', array($this, 'salcodes_year') );
            
        }

    OR

    The code2 (moving to__construct()):

    function __construct()
        {
           require_once plugin_dir_url(__FILE__) . 'src/ming_crawler.php';
        }

    No matter which I move to code1 or code2, I got same error.
    Could you help me, thanks

    • This reply was modified 2 years, 6 months ago by nobody123.
    Thread Starter nobody123

    (@nobody123)

    I got this error after moving the code withinjs2php_register()
    Fatal error: Uncaught Error: Class 'Test_one' not found in D:\Appserv\Apache24\htdocs\php7.4\wordpress\wp-content\plugins\crawler\crawler.php:176 Stack trace: #0 D:\Appserv\Apache24\htdocs\php7.4\wordpress\wp-content\plugins\crawler\crawler.php(183): Test->js2php_register() #1 D:\Appserv\Apache24\htdocs\php7.4\wordpress\wp-settings.php(409): include_once('D:\\Appserv\\Apac...') #2 D:\Appserv\Apache24\htdocs\php7.4\wordpress\wp-config.php(96): require_once('D:\\Appserv\\Apac...') #3 D:\Appserv\Apache24\htdocs\php7.4\wordpress\wp-load.php(50): require_once('D:\\Appserv\\Apac...') #4 D:\Appserv\Apache24\htdocs\php7.4\wordpress\wp-admin\admin.php(34): require_once('D:\\Appserv\\Apac...') #5 D:\Appserv\Apache24\htdocs\php7.4\wordpress\wp-admin\index.php(10): require_once('D:\\Appserv\\Apac...') #6 {main}

    The following is my code:

    class Test{
        private $infos;
        
        function get_info() {
            if ( isset($_REQUEST['my_info']) ) {
        
                $infos = $_REQUEST['my_info'];
                if (get_option('my_url')){
                    update_option('my_url', $infos);
                }else{
                    add_option('my_url', $infos);
                }
            }
            die();
        }
        
        function salcodes_year() {
            return get_option('my_url');        
        }
    
        function js2php_register(){
            add_action( 'wp_ajax_crawler_info', array($this, 'get_info') );
            add_action( 'wp_ajax_nopriv_crawler_info', array($this, 'get_info') );        
            require_once plugin_dir_url(__FILE__) . 'src/ming_crawler.php';
            $this->my_crawler = new Test_one(get_option('my_val'));
            add_shortcode( 'current_year', array($this, 'salcodes_year') );
        }
        
    }
    $test = new Test;
    $test->js2php_register();
    Thread Starter nobody123

    (@nobody123)

    I got this error after moving the code within a constructor function of Test

    Fatal error: Uncaught Error: Class 'Test_one' not found in D:\Appserv\Apache24\htdocs\php7.4\wordpress\wp-content\plugins\crawler\crawler.php:131 Stack trace: #0 D:\Appserv\Apache24\htdocs\php7.4\wordpress\wp-content\plugins\crawler\crawler.php(185): Test->__construct() #1 D:\Appserv\Apache24\htdocs\php7.4\wordpress\wp-settings.php(409): include_once('D:\\Appserv\\Apac...') #2 D:\Appserv\Apache24\htdocs\php7.4\wordpress\wp-config.php(96): require_once('D:\\Appserv\\Apac...') #3 D:\Appserv\Apache24\htdocs\php7.4\wordpress\wp-load.php(50): require_once('D:\\Appserv\\Apac...') #4 D:\Appserv\Apache24\htdocs\php7.4\wordpress\wp-admin\admin.php(34): require_once('D:\\Appserv\\Apac...') #5 D:\Appserv\Apache24\htdocs\php7.4\wordpress\wp-admin\index.php(10): require_once('D:\\Appserv\\Apac...') #6 {main}

    The following is my code:

    class Test{
        private $infos;
        
        function __construct()
        {
            add_action( 'wp_ajax_crawler_info', array($this, 'get_info') );
            add_action( 'wp_ajax_nopriv_crawler_info', array($this, 'get_info') );        
            require_once plugin_dir_url(__FILE__) . 'src/ming_crawler.php';
            $this->my_crawler = new Test_one(get_option('my_val'));
        }
      
        function get_info() {
            if ( isset($_REQUEST['my_info']) ) {
        
                $infos = $_REQUEST['my_info'];
                if (get_option('my_url')){
                    update_option('my_url', $infos);
                }else{
                    add_option('my_url', $infos);
                }
            }
            die();
        }
        
        function salcodes_year() {
            return get_option('my_url');        
        }
    
        function js2php_register(){
            add_shortcode( 'current_year', array($this, 'salcodes_year') );
        }
        
    }
    $test = new Test;
    $test->js2php_register();
    Thread Starter nobody123

    (@nobody123)

    So….how do I fix this question?
    Thank you

    Thread Starter nobody123

    (@nobody123)

    @bcworkz
    1. I found $this->val can’t work in the function of add_action or add_shortcode in the same class.
    Therefore, $my_crawler = new Test_one($infos); should change to $my_crawler = new Test_one(get_option('my_val'));

    2. I get error Fatal error: Uncaught Error: Class ‘Test_one’ not found when I run my code.
    The following is my_test1.php:

    <?php
    class Test_one{
        function a(){
            $this->a1='aaa';
        }
        function b(){
            echo 'a1:'.$this->a1;
        }
        function c(){
            $this->a();
            $this->b();
        }
    }

    3. my file directory:
    The class of Test is in my_plugin_name.php

    my_plugin_name—assets
    | |
    | —js
    | |
    | –app.js
    |
    —src
    | |
    | –my_test1.php
    |
    |
    —my_plugin_name.php

    • This reply was modified 2 years, 6 months ago by nobody123.
    Thread Starter nobody123

    (@nobody123)

    @bcworkz No, I mean display value using PHP, not JS.
    First, our discuss base on wordpress plugin, so we can display value on plugin page using php’s echo.
    Second, the process is the following
    html value –1–> JS get this value –2–> JS delivers this value using ajax–3–> php gets this value using wp_ajax_ –4–> displaying this value using php echo (This means php gets this value truly, and then I can handle this value or doing another testing)

    Another word, I don’t know how to modify your code to the 4th step.

    Thread Starter nobody123

    (@nobody123)

    @bcworkz I know what you said, and thank for your explain.
    but my main problem is how to display echo the vale on the frontend of admin or wp after ajax deliver it.

    Thread Starter nobody123

    (@nobody123)

    @bcworkz Thanks for your explain, but I more want to how to get value in php from ajax not only get value in $ajax.do.
    Do you know how to get?

Viewing 15 replies - 1 through 15 (of 21 total)