Hot answers tagged

6

If the plugin structure is: plugins/ some-plugin/ some-plugin.php data/ GeoIP.dat then for PHP 5.3.0+, you could try the magic constant __DIR__ __DIR__ The directory of the file. If used inside an include, the directory of the included file is returned. This is equivalent to dirname(__FILE__). This directory name does ...


4

You can use: plugin_dir_path(__FILE__); Which as is just a wrapper function anyway for: trailingslashit(dirname(__FILE__));


3

There are several points which should be clear when starting such a project. WordPress is constantly updating, think about extra layer protection through updates or changes in the GUI. (meaning by that, updating core files) A plugin relies on Wordpress core, which need to be updated also when there are changes which can cause conflicts. In worse case it ...


2

get_template_directory_uri works in a plugin, in that it returns the active theme directory URI, which is what the template directory is. If you're trying to get the URI for your plugin assets, then you want plugin_dir_url. wp_enqueue_script( 'jquery-repeater-form', plugin_dir_url( __FILE__ ) . 'js/sample.js' );


2

You could also have a look at the functions WordPress has on board for this: e.g. plugin_dir_path(), plugins_url() or plugin_dir_url() They will help you with determining where your plugin is placed on the server. Those functions are also recommended by the Codex in Writing a Plugin: Names, Files, and Locations. Besides that you can obviously use magic ...


2

Well, AUTH_KEY and it´s brothers where introduced in WordPress 2.6 to improve safety for logged in users. They are used to encrypt and validate the information in your backend login cookie. While revealing the AUTH_KEY alone might not be a real security issue, you should nevertheless not output/use this anywhere to give less surface for attacks. ...


2

A way to do it is to use the (very convenient) editor:image-edit and editor:image-update events triggered by the tinymce wpeditimage plugin to get/set the dom directly: add_action( 'admin_footer', function () { ?> <script type="text/javascript"> jQuery(function ($) { if (wp && wp.media && wp.media.events) { ...


1

I have solved my problem by adding $myCode -> change_url(); and add_action('wp_head', array($myCode, 'print_header_scripts')); <?php class some_code { function change_url() { $domain_name = $_SERVER['SERVER_NAME']; $country_code = get_country_code(); if ($country_code == "PK") { header("location: ...


1

No idea why the change of folder name makes a difference, but you should add jquery as dependency in your enqueue wp_enqueue_script( 'wtfjs', plugins_url( '/js/wtf.js' , __FILE__), array('jquery') );



Only top voted, non community-wiki answers of a minimum length are eligible