how to create public file in wp plugin to access it from other apps?












1















I want to write a plugin so that I can connect to it with an app bot, and store information inside the database.



Note that because I directly connect to php file inside this plugin, the public WordPress values like $wpdb are not known.



And how can i access to wp functions? such as get_option,...



thanks for your help.










share|improve this question



























    1















    I want to write a plugin so that I can connect to it with an app bot, and store information inside the database.



    Note that because I directly connect to php file inside this plugin, the public WordPress values like $wpdb are not known.



    And how can i access to wp functions? such as get_option,...



    thanks for your help.










    share|improve this question

























      1












      1








      1








      I want to write a plugin so that I can connect to it with an app bot, and store information inside the database.



      Note that because I directly connect to php file inside this plugin, the public WordPress values like $wpdb are not known.



      And how can i access to wp functions? such as get_option,...



      thanks for your help.










      share|improve this question














      I want to write a plugin so that I can connect to it with an app bot, and store information inside the database.



      Note that because I directly connect to php file inside this plugin, the public WordPress values like $wpdb are not known.



      And how can i access to wp functions? such as get_option,...



      thanks for your help.







      wordpress custom-wordpress-pages






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 27 '18 at 18:50









      Hamed BHamed B

      266




      266
























          1 Answer
          1






          active

          oldest

          votes


















          0














          Maybe this helps you



          require_once( 'path to wordpress project root'. '/wp-load.php' );

          // Set up the WordPress query.
          wp();


          For example if you want to create plugin with name - test




          1. You need to create a directory with name 'test' inside plugin directory wp-content/plugins/test

          2. Then you need to create file test.php - it is the main file of your plugin


          3. Then you need to add at beginning of your test.php file after comments require wp-load if WordPress environment is not included (it is your case when you call your file directly)
            For example, your plugin main file is wp-content/plugins/test/test.php starts with this snippet and before this snippet, you need to place your plugin metadata like name - description and so on. I recommend to download WordPress and see default plugins meta in wp-content/plugins/askimet/askimet.php and wp-content/plugins/hello.php.



            if ( !defined('ABSPATH') ) {
            /** Set up WordPress environment */
            require_once( '../../wp-load.php' );
            }
            then you can use get_option() $wpdb and other wp functions.



            wp() function in my previous answer need for initializing global wp query. It is not necessary. You can create your own wp query by using WP_Query class.
            https://codex.wordpress.org/Class_Reference/WP_Query - there is description with examples how to use WP_Query.



          4. Then You can write your plugin in OOP or functional style. You can write your plugin analogically to Askimet for example or with boilerplates. This is the question about plugin development. Hope this question helps you achieve your purpose.
            https://wordpress.stackexchange.com/questions/85486/is-there-any-plugin-development-framework



          Hope this help you






          share|improve this answer


























          • i use 4.9.8 wp version,and i check your directory,but not exists wp-load.php file.

            – Hamed B
            Nov 27 '18 at 19:15








          • 1





            hm, wp-load.php need to be in one level as directories wp-admin, wp-content, wp-includes, do you have wp-confing.php file and you have no wp-load.php around wp-config.php ? I have wp-load.php file after wp-cron.php

            – sftt
            Nov 27 '18 at 21:31






          • 1





            thanks @searcherforthe i found file!! Can you give a simple example of wp? please.

            – Hamed B
            Nov 28 '18 at 6:36






          • 1





            I have provided description for plugin development

            – sftt
            Nov 29 '18 at 3:30











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53506298%2fhow-to-create-public-file-in-wp-plugin-to-access-it-from-other-apps%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          Maybe this helps you



          require_once( 'path to wordpress project root'. '/wp-load.php' );

          // Set up the WordPress query.
          wp();


          For example if you want to create plugin with name - test




          1. You need to create a directory with name 'test' inside plugin directory wp-content/plugins/test

          2. Then you need to create file test.php - it is the main file of your plugin


          3. Then you need to add at beginning of your test.php file after comments require wp-load if WordPress environment is not included (it is your case when you call your file directly)
            For example, your plugin main file is wp-content/plugins/test/test.php starts with this snippet and before this snippet, you need to place your plugin metadata like name - description and so on. I recommend to download WordPress and see default plugins meta in wp-content/plugins/askimet/askimet.php and wp-content/plugins/hello.php.



            if ( !defined('ABSPATH') ) {
            /** Set up WordPress environment */
            require_once( '../../wp-load.php' );
            }
            then you can use get_option() $wpdb and other wp functions.



            wp() function in my previous answer need for initializing global wp query. It is not necessary. You can create your own wp query by using WP_Query class.
            https://codex.wordpress.org/Class_Reference/WP_Query - there is description with examples how to use WP_Query.



          4. Then You can write your plugin in OOP or functional style. You can write your plugin analogically to Askimet for example or with boilerplates. This is the question about plugin development. Hope this question helps you achieve your purpose.
            https://wordpress.stackexchange.com/questions/85486/is-there-any-plugin-development-framework



          Hope this help you






          share|improve this answer


























          • i use 4.9.8 wp version,and i check your directory,but not exists wp-load.php file.

            – Hamed B
            Nov 27 '18 at 19:15








          • 1





            hm, wp-load.php need to be in one level as directories wp-admin, wp-content, wp-includes, do you have wp-confing.php file and you have no wp-load.php around wp-config.php ? I have wp-load.php file after wp-cron.php

            – sftt
            Nov 27 '18 at 21:31






          • 1





            thanks @searcherforthe i found file!! Can you give a simple example of wp? please.

            – Hamed B
            Nov 28 '18 at 6:36






          • 1





            I have provided description for plugin development

            – sftt
            Nov 29 '18 at 3:30
















          0














          Maybe this helps you



          require_once( 'path to wordpress project root'. '/wp-load.php' );

          // Set up the WordPress query.
          wp();


          For example if you want to create plugin with name - test




          1. You need to create a directory with name 'test' inside plugin directory wp-content/plugins/test

          2. Then you need to create file test.php - it is the main file of your plugin


          3. Then you need to add at beginning of your test.php file after comments require wp-load if WordPress environment is not included (it is your case when you call your file directly)
            For example, your plugin main file is wp-content/plugins/test/test.php starts with this snippet and before this snippet, you need to place your plugin metadata like name - description and so on. I recommend to download WordPress and see default plugins meta in wp-content/plugins/askimet/askimet.php and wp-content/plugins/hello.php.



            if ( !defined('ABSPATH') ) {
            /** Set up WordPress environment */
            require_once( '../../wp-load.php' );
            }
            then you can use get_option() $wpdb and other wp functions.



            wp() function in my previous answer need for initializing global wp query. It is not necessary. You can create your own wp query by using WP_Query class.
            https://codex.wordpress.org/Class_Reference/WP_Query - there is description with examples how to use WP_Query.



          4. Then You can write your plugin in OOP or functional style. You can write your plugin analogically to Askimet for example or with boilerplates. This is the question about plugin development. Hope this question helps you achieve your purpose.
            https://wordpress.stackexchange.com/questions/85486/is-there-any-plugin-development-framework



          Hope this help you






          share|improve this answer


























          • i use 4.9.8 wp version,and i check your directory,but not exists wp-load.php file.

            – Hamed B
            Nov 27 '18 at 19:15








          • 1





            hm, wp-load.php need to be in one level as directories wp-admin, wp-content, wp-includes, do you have wp-confing.php file and you have no wp-load.php around wp-config.php ? I have wp-load.php file after wp-cron.php

            – sftt
            Nov 27 '18 at 21:31






          • 1





            thanks @searcherforthe i found file!! Can you give a simple example of wp? please.

            – Hamed B
            Nov 28 '18 at 6:36






          • 1





            I have provided description for plugin development

            – sftt
            Nov 29 '18 at 3:30














          0












          0








          0







          Maybe this helps you



          require_once( 'path to wordpress project root'. '/wp-load.php' );

          // Set up the WordPress query.
          wp();


          For example if you want to create plugin with name - test




          1. You need to create a directory with name 'test' inside plugin directory wp-content/plugins/test

          2. Then you need to create file test.php - it is the main file of your plugin


          3. Then you need to add at beginning of your test.php file after comments require wp-load if WordPress environment is not included (it is your case when you call your file directly)
            For example, your plugin main file is wp-content/plugins/test/test.php starts with this snippet and before this snippet, you need to place your plugin metadata like name - description and so on. I recommend to download WordPress and see default plugins meta in wp-content/plugins/askimet/askimet.php and wp-content/plugins/hello.php.



            if ( !defined('ABSPATH') ) {
            /** Set up WordPress environment */
            require_once( '../../wp-load.php' );
            }
            then you can use get_option() $wpdb and other wp functions.



            wp() function in my previous answer need for initializing global wp query. It is not necessary. You can create your own wp query by using WP_Query class.
            https://codex.wordpress.org/Class_Reference/WP_Query - there is description with examples how to use WP_Query.



          4. Then You can write your plugin in OOP or functional style. You can write your plugin analogically to Askimet for example or with boilerplates. This is the question about plugin development. Hope this question helps you achieve your purpose.
            https://wordpress.stackexchange.com/questions/85486/is-there-any-plugin-development-framework



          Hope this help you






          share|improve this answer















          Maybe this helps you



          require_once( 'path to wordpress project root'. '/wp-load.php' );

          // Set up the WordPress query.
          wp();


          For example if you want to create plugin with name - test




          1. You need to create a directory with name 'test' inside plugin directory wp-content/plugins/test

          2. Then you need to create file test.php - it is the main file of your plugin


          3. Then you need to add at beginning of your test.php file after comments require wp-load if WordPress environment is not included (it is your case when you call your file directly)
            For example, your plugin main file is wp-content/plugins/test/test.php starts with this snippet and before this snippet, you need to place your plugin metadata like name - description and so on. I recommend to download WordPress and see default plugins meta in wp-content/plugins/askimet/askimet.php and wp-content/plugins/hello.php.



            if ( !defined('ABSPATH') ) {
            /** Set up WordPress environment */
            require_once( '../../wp-load.php' );
            }
            then you can use get_option() $wpdb and other wp functions.



            wp() function in my previous answer need for initializing global wp query. It is not necessary. You can create your own wp query by using WP_Query class.
            https://codex.wordpress.org/Class_Reference/WP_Query - there is description with examples how to use WP_Query.



          4. Then You can write your plugin in OOP or functional style. You can write your plugin analogically to Askimet for example or with boilerplates. This is the question about plugin development. Hope this question helps you achieve your purpose.
            https://wordpress.stackexchange.com/questions/85486/is-there-any-plugin-development-framework



          Hope this help you







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 29 '18 at 3:36

























          answered Nov 27 '18 at 18:57









          sfttsftt

          54329




          54329













          • i use 4.9.8 wp version,and i check your directory,but not exists wp-load.php file.

            – Hamed B
            Nov 27 '18 at 19:15








          • 1





            hm, wp-load.php need to be in one level as directories wp-admin, wp-content, wp-includes, do you have wp-confing.php file and you have no wp-load.php around wp-config.php ? I have wp-load.php file after wp-cron.php

            – sftt
            Nov 27 '18 at 21:31






          • 1





            thanks @searcherforthe i found file!! Can you give a simple example of wp? please.

            – Hamed B
            Nov 28 '18 at 6:36






          • 1





            I have provided description for plugin development

            – sftt
            Nov 29 '18 at 3:30



















          • i use 4.9.8 wp version,and i check your directory,but not exists wp-load.php file.

            – Hamed B
            Nov 27 '18 at 19:15








          • 1





            hm, wp-load.php need to be in one level as directories wp-admin, wp-content, wp-includes, do you have wp-confing.php file and you have no wp-load.php around wp-config.php ? I have wp-load.php file after wp-cron.php

            – sftt
            Nov 27 '18 at 21:31






          • 1





            thanks @searcherforthe i found file!! Can you give a simple example of wp? please.

            – Hamed B
            Nov 28 '18 at 6:36






          • 1





            I have provided description for plugin development

            – sftt
            Nov 29 '18 at 3:30

















          i use 4.9.8 wp version,and i check your directory,but not exists wp-load.php file.

          – Hamed B
          Nov 27 '18 at 19:15







          i use 4.9.8 wp version,and i check your directory,but not exists wp-load.php file.

          – Hamed B
          Nov 27 '18 at 19:15






          1




          1





          hm, wp-load.php need to be in one level as directories wp-admin, wp-content, wp-includes, do you have wp-confing.php file and you have no wp-load.php around wp-config.php ? I have wp-load.php file after wp-cron.php

          – sftt
          Nov 27 '18 at 21:31





          hm, wp-load.php need to be in one level as directories wp-admin, wp-content, wp-includes, do you have wp-confing.php file and you have no wp-load.php around wp-config.php ? I have wp-load.php file after wp-cron.php

          – sftt
          Nov 27 '18 at 21:31




          1




          1





          thanks @searcherforthe i found file!! Can you give a simple example of wp? please.

          – Hamed B
          Nov 28 '18 at 6:36





          thanks @searcherforthe i found file!! Can you give a simple example of wp? please.

          – Hamed B
          Nov 28 '18 at 6:36




          1




          1





          I have provided description for plugin development

          – sftt
          Nov 29 '18 at 3:30





          I have provided description for plugin development

          – sftt
          Nov 29 '18 at 3:30




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53506298%2fhow-to-create-public-file-in-wp-plugin-to-access-it-from-other-apps%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Contact image not getting when fetch all contact list from iPhone by CNContact

          count number of partitions of a set with n elements into k subsets

          A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks