Hot answers tagged

7

There is plugin_basename() call some levels inside which seems to use WP_PLUGIN_DIR and WPMU_PLUGIN_DIR constants, so my guess would be this function is only meant to be used for things inside plugin directories and not other places like theme.


5

Use plugin_dir_url() to get the public URI for the directory where the calling PHP file is. <img src="<?php echo plugin_dir_url( __FILE__ ) . 'images/facebook.png'; ?>"> If the PHP file is in a sub directory of your plugin you have to go up: <img src="<?php echo plugin_dir_url( dirname( __FILE__ ) ) . 'images/facebook.png'; ?>">


4

Yes, any of those are possible and configurable under Settings > Permalinks. Have a look at the Permalinks page for other possibilities. One thing to note though, it's suggested to add a number at the beginning of your permalinks to reduce the number of rewrite rules WordPress has to generate to resolve all of your URLs. The permalink strings for your ...


4

__DIR__ is rather new and not always supported. Use dirname( __FILE__ ). plugins_url() is using … $folder = dirname(plugin_basename($plugin)); … so yes, it is safe. Just use plugins_url( 'subfolder/file.css', dirname( __FILE__ ) )


3

This is a PHP issue, not specific to WordPress. I suggest reading the PHP documentation on variable scope to understand why this doesn't work. There is no $plugin_url variable defined within the scope of your my_jquery_enqueue function, you would have to call global $plugin_url; first within the function to access it, though I don't suggest using something ...


3

Filter category_link so WordPress creates slashed URLs for categories, and redirect_canonical so it accepts those URLs: add_filter( 'category_link', 'wpse_71666_trailingslash_cat_url' ); add_filter( 'redirect_canonical', 'wpse_71666_trailingslash_cat_url', 20, 2 ); function wpse_71666_trailingslash_cat_url( $url, $request = '' ) { if ( 'category_link' ...


3

function add_my_css_and_my_js_files(){ wp_enqueue_script('jquery-validate-min', plugins_url('activate/jquery_validate_min.js', __FILE__ ) ); } add_action('wp_enqueue_scripts', "add_my_css_and_my_js_files"); You need to use the plugins_url() function (you are missing the s at the end of plugins). Reference the location of the script file with the ...


3

The function you are looking for is called plugins_url() (ref), with the additional s. Should be fine afterwards.


2

There is plugin_dir_path(), but it's not exact analogue of plugins_url(). Also ABSPATH is unreliable for how you use it, related paths can be easily redefined. See default-constants.php file. Namely there are: WP_CONTENT_DIR WP_PLUGIN_DIR WPMU_PLUGIN_DIR


2

I got a little piece of code here, but it should/could probably be improved. Create new query_vars Create new rewrite rule Redirect to specific template which then handles your parameters Create new query vars function register_gallery_query_vars($vars) { $vars[] = 'gallery_id'; $vars[] = 'image_id'; return $vars; } add_filter('query_vars', ...


2

What my ultimate goal is, other plugins be it infected(backdoor etc) or not cannot access the username/password/mail of my email, that is the main part of the question. The only way to be sure of this is to not store them in a manner than can be automatically decrypted in the database/filesystem - which is to say, not store them in plain-text or an ...


2

I assume the issue is that your form targets an external file, where WordPress isn't properly loaded to access the API. WordPress has a handler built in that you can use to process POST requests, via the admin_post action: Example form with hidden action field: <form action="<?php echo admin_url( 'admin-post.php' ); ?>" method="post"> ...


1

I am not sure I follow your question, title seems different from question itself. You seem to want to get rid of index.php in URL? It's hard to say confidently from outside, but it looks like PATHINFO permalink. If that's the case you would need to change your WP permalink configuration to more common "pretty" one. Doesn't have anything to do with CPT's ...


1

Just don't do it, you can never know if the plugins directory is even "below" ABSPATH, and you can not know the URL out of the directory path https://codex.wordpress.org/Determining_Plugin_and_Content_Directories. Just use the core api of plugins_utl etc, don't reinvent the wheel.


1

First you need to register your expected variables. Something similar to: function my_rewrite() { add_rewrite_tag('%ct_city%', '([^&]+)'); add_rewrite_tag('%country%', '([^&]+)'); } add_action('init', 'my_rewrite', 10, 0); Then you need to create the rule which will redirect to your abm page. Note that you will need to discover your ...


1

Here a very quick example. The idea is to add a new meta box in the menu configuration. add_meta_box is used in admin_head-nav-menus.php page: class Custom_Nav { function __construct() { add_action( 'admin_head-nav-menus.php', array( $this, 'add_nav_menu_meta_boxes' ) ); } public function add_nav_menu_meta_boxes() { add_meta_box( ...


1

Masonry is already registered by WordPress. From wp-includes/script-loader.php: // Masonry v2 depended on jQuery. v3 does not. The older jquery-masonry handle is a shiv. // It sets jQuery as a dependency, as the theme may have been implicitly loading it this way. $scripts->add( 'masonry', "/wp-includes/js/masonry.min.js", array(), '3.1.2', 1 ); ...


1

This line is your problem: $new_site_name = $site_name . '<sup>echo '<img src="' . plugins_url( 'images/wordpress.png' ,"logo.jpg" ) . '" > '</sup>'; Here you've muddled up the quotes and put PHP code inside a string expecting it to still work. e.g. echo ' this is inside a quote:' inside a quote ' . '; It doesn't work because the ...


1

You could try something like if( ! function_exists('plugin_function') ) require_once('/wp-content/plugins/wp-recaptcha/recaptchalib.php'); endif; Not tested but essentially it checks if the plugin exists before trying to add it


1

Use if( file_exists(plugin_dir_path(__FILE__) . 'myfile.ext') ) {} instead of if( file_exists( plugins_url( "myfile.ext", __FILE__ ) ) ) {} See plugin_dir_path in the Codex.


1

Just use the domain mapping plugin. It odes what you want and yes it works on subfolder sites.


1

This is straightforward if I understand the question properly. Use the "WordPress MU Domain Mapping" plugin: http://wordpress.org/extend/plugins/wordpress-mu-domain-mapping/ Update I think something like the following should work in your .htaccess: RewriteCond %{HTTP_HOST} www.exampleurl.com RewriteCond %{REQUEST_URI} !^/testsite RewriteRule ^(.*)$ ...


1

Create a custom page template: <?php /** * Template Name: Random PHP */ get_header(); //add random PHP get_sidebar(); get_footer(); ?> Create a page in WordPress, give it the title portfolio. In the template select box choose Random PHP


1

You can try to override it by using the following in config.php and see if it works as it will update your database, doing so will make it unable to be changed in your admin (it will be greyed out). define('WP_SITEURL', 'http://example.com/'); And some alternative definitions, http://codex.wordpress.org/Editing_wp-config.php#WordPress_address_.28URL.29 ...


1

The plugins_url() function builds a URL string based on the Site URL you have configured. Remember, WordPress URL and Site URL are two different things. plugins_url() is merely a concatenation of: get_option( 'site_url' ) /wp-content The folder of the plugin So if you're seeing a www in your site, it's because site_url is set to use a www.


1

There aren't any for plugins, but you can (and should) use WP_CONTENT_DIR, instead of ABSPATH. For themes you have locate_template().



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