New answers tagged

1

I got it. It kind of makes sense but doesnt really. The one template wasnt working becuase I was looking for just the slug. Since its a child of the other page I needed to add it in the is_page statement. This worked (I also just did it all in one function): function ch_register_page_template($page_template;) {////////////////<-------------Works if ...


0

Both of your filters return nothing if the conditional doesn't match, so if the first one matches, it's broken by the one that runs after it. Remember that filters are dealing with some sort of value that is passed through them. Your filters should pass back the unaltered template that was passed to them as function argument if the conditional doesn't ...


5

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


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 ...


8

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 ...


3

Custom tables can simplify your code, improve performance and help avoiding conflicts with WordPress’ schema changes in the future. Don’t hesitate to use one if you need it. The extra complexity comes from two other factors: maintenance and multisite. Maintenance: manual or automatic backups might omit custom tables, so there is a tiny risk that the data ...


0

In fact, adding db table is not very much that expensive as you think. If you configure it well. Suppose, before you create the table it is really you need it. If so, you just need to follow up wordpress database creating table standard. They have their guide line. Another thing to note, you database table never ever should hurt wordpress core functionality. ...


0

Your code is being executed too early before the "base" query was evaluated. As a thumb rule, in a plugin always hook your code to an appropriate hook, probably wp_loaded is best if there is nothing more specific


1

Question 1. so where it is defined before Answer: It is defined in WordPress core. Here a quick online reference or for a local reference take a look at the following file in the root of WordPress: wp-settings.php. In that file (around line 18) following code is shown: define( 'WPINC', 'wp-includes' ); Question 2. and it is not abort the ...


1

WPINC is defined by WP before plugins are loaded; so, the fact that it is already defined indicates the plugin is being loaded by WP rather than a direct request.


0

Use the checked function. https://codex.wordpress.org/Function_Reference/checked The HTML you want to render should look like this: <input ... value="hide" checked="checked" />Hide from these locations.</br> <input ... value="show" />Only show to these locations.</br> What you're getting instead is probably somthing like this: ...


0

If you need admin pages that don't appear in the menu, use add_submenu_page and set $parent to null. This will create a functional page that doesn't get rendered in the menu. add_action( 'admin_menu', 'wpd_hidden_plugin_submenu_page' ); function wpd_hidden_plugin_submenu_page() { add_submenu_page( null, 'My Hidden Submenu Page', ...


0

Unfortunately the slug is returned via the Update API, the answer to this question is not so obvious unless you query the API itself. However, if you want to see a list of your current plugin slugs and related plugin data you can simply do: print_r(get_site_transient('update_plugins')); But, this will not have info on a newly installed plugin for another ...


2

Your code seems correct, but it will load the script only in admin area beacuse you are enqueuing the script in admin_enqueue_scripts action. To load the script in frontend, use wp_enqueue_scripts action (which is not the same that wp_enqueue_script() function): function Zumper_widget_enqueue_script() { wp_enqueue_script( 'my_custom_script', ...


0

UPDATED: Use this code instead function Zumper_widget_enqueue_script() { wp_enqueue_script( 'my_custom_script', plugin_dir_url( __FILE__ ) . 'js/jquery.repeatable.js', array('jquery'), '1.0.0', false ); } add_action('admin_enqueue_scripts', 'Zumper_widget_enqueue_script'); 3rd parameter is to declare dependency and 4th one is to define version. ...


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

This is just a typo Wrong //wvdh-startpoint add_submenu_page( 'wvdh-startpoint', 'page-from-plugin', 'menu-from-plugin', 'manage_options', 'plugin-slug', 'wvdh_settings_page' ); Correct //wdvh-startpoint add_submenu_page( 'wdvh-startpoint', 'page-from-plugin', 'menu-from-plugin', 'manage_options', 'plugin-slug', 'wvdh_settings_page' );


0

Use add_submenu_page and set $parent_slug to null: add_action('admin_menu', 'wpdocs_register_my_custom_submenu_page'); function wpdocs_register_my_custom_submenu_page() { add_submenu_page( null, 'My Custom Submenu Page', 'My Custom Submenu Page', 'manage_options', 'my-custom-submenu-page', ...


0

If your mu-plugin has options I would put the flush right after updating them: update_option( 'my_options', $values ); // Flush rules after install flush_rewrite_rules();


0

Yes, you could. I had done something similar using the Eyes-Only plugin. Create a user type for each department. Create an architecture for each department. - Menus - Pages - Custom post types Select department managers Create a query where department-admin can only see users of the same department. This does require extensive work to get cross ...


0

You don't need this global $bp; Try passing an array: $id = 1; $args = array( 'group_id' => $id, 'exclude_admins_mods' => false); if ( bp_group_has_members( $args ) ) :


0

Using your comments, I found what I was missing. I initialized my textdomain with : add_action('admin_init', 'related_post_shortcode_init'); function related_post_shortcode_init() { load_plugin_textdomain('related-post-shortcode', false, basename( dirname( __FILE__ ) ) . '/i18n' ); } So, the textdomain was ok and ready for back-office translations ...


0

Managed to solve my own issue. Simply paste the following into functions.php function custom_wc_ajax_variation_threshold( $qty, $product ) { return 10; } add_filter( 'woocommerce_ajax_variation_threshold', 'custom_wc_ajax_variation_threshold', 10, 2 ); Then change the 'return 10;' to however many variations you have. Please note this may slow ...


0

If you go with @Rituparna's solution, try this: Don't forget to add <a href="#" class="close">X</a> in your container. jQuery(function($){ $(".plink").on('click', function( event ){ event.preventDefault(); // cache the link clicked on var link = $(event.target); // use the link attr to target the desc ...


0

<div class="row"> <?php $args = array('post_type' => 'team', 'category_name' => $a); $query = new WP_Query($args); if ($query->have_posts()) { while ($query->have_posts()) { $query->the_post(); ?> <div class="tab_heading col-md-4"> <div class="wrapper"> <a class="plink" href="#tab-<?php echo ...


0

$arr['Zumpito_event_full_day'] = isset( $_POST['Zumpito_event_full_day'] ) ? esc_attr( $_POST['Zumpito_event_full_day]) : ''; this should solve your first notice explanation is this in the link given by you


0

PHPStorm and Xdebug is a game changing for me for WordPress development. Highly recommend now. Specially with theirs inline debug tools.


0

I was missing a crucial line in my AJAX query. Without this option, the call fails, and the pages refreshes. processData: false,


0

Escaping is used to produce valid HTML or other formats, and it depends on context. Escaping a url in something like <a href="<?php echo $url?>".... is needed in order to replace any "&" characters with & (although browsers will most likely fix it for you if you don't do it). Escaping a url in an input element like <input ...


2

You should always escape your data, whatever its origin. For your example, the URLs should be escaped using esc_url(). WordPress has many functions which can be used. There's an article on Data validation on the Codex which lists the various functions available.


3

Try using preventDefault(), it's a jQuery function for preventing default actions called by the browser. First you should call an event handler by firing up your submitter. You can do this as follow: $('#my_upload_form').submit(function (event) { After catching a submit and giving an event with it, you should prevent the default refresh of a browser: ...


1

Capabilities are stored in database, that is why they keep active even if you remove your function. Capabilities need to be expressly removed: $admin = get_role('author'); $admin->remove_cap( 'edit_teacher' ); And, because they are stored in database, you should stop adding them in every page load (as you are doing in init event). Usually, you should ...


0

wp_create_user is your friend! It takes a username, password, and email: wp_create_user( $username, $password, $email ); And here's an example: $user_id = username_exists( $user_name ); if ( !$user_id and email_exists($user_email) == false ) { $random_password = wp_generate_password( $length=12, $include_standard_special_chars=false ); $user_id ...


1

Use: get_template_directory() and or get_stylesheet_directory() E.g. in zumper/layouts/america.php <?php include get_template_directory() . '/inc/york.php'; //etc... Note: get_template_directory Retrieves the absolute path to the directory of the current theme. get_stylesheet_directory Retrieve stylesheet directory Path for the current ...


0

So I found the solution: copy("http://localhost/medium/theme.zip", get_theme_root() . "/themenew.zip");


0

The authentication was done by creating a wp_validate_auth_cookie function and calling it. if ( ! function_exists( 'wp_validate_auth_cookie' ) ) : function wp_validate_auth_cookie( $cookie = '', $scheme = '' ) { if ( XenWord::getVisitor()->getUserId() != 0 ) { return XenWord::getVisitor()->getUserId(); } return false; } endif; ...


6

The answer lies within the wp_get_current_user() pluggable function. I simply changed the function name get_currentuserinfo() to wp_get_current_uesr() then made sure the returns were not boolean but return $current_user. This seems to be working well, including caching, etc. Hopefully this helps others. if ( ! function_exists( 'wp_get_current_user' ) ) : ...


0

In the end i used this- // Define global variables global $am_globals; $am_globals = array( 'if_autoload' => get_option( 'autoload-or-shortcode' ), ); and this- if( ! $if_autoload = $GLOBALS['am_globals']['if_autoload'] ) {


1

50 is relatively not much, and you should create them on the plugin activation hook. For more then 100 (just pulled the number out of my ass ;) do your own testing on some slow shared hosting) I would create a settings page and initialize the DB from there. The reason is that users do not expect plugin activation to take long and might think that something ...


0

Save yourself a headache and make a class. The static variable can be accessed like a global once it's loaded. Just be sure the class exists before you try to use it! if ( ! class_exists( 'WPSE_20150123_Plugin' ) ) { class WPSE_20150123_Plugin { // our variable that will be set and read back later public static $if_autoload = 'I\'m Not ...


0

You may take use of add_submenu_page function: Add a top-level menu page add_menu_page( $page_title, $menu_title, $capability, $menu_slug, $function, $icon_url, $position ); Add a sub-menu page add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug, $function );


0

Personally, I like to do something like this as Error Reporting. When something goes wrong - in the PHP function - set an Error Header that will return back to your JQuery along with a string message: header( 'HTTP/1.1 400 Empty Attachment' ); echo 'Could Not Upload File.'; exit; To classify this as an error header you need HTTP/1.1 400 but after that you ...


0

You can try the following function to insert image to a post. Note: The following function will not make the image "featured image". It will just uploaded the image and attach it to the post. It will return the attachment id if the upload is successful function insert_post_media( $post_id, $url){ $tmp = download_url( $url ); $file_array ...


0

Use get_option() instead. The get_option() method returns an option for the current blog. In single site installation, the current blog is the only blog. So get get_option() returns the option for it.


1

You can pass an array of settings to the editor instance. For possible values please refer to the tinymce documentation, in your case 'init_instance_callback' might be helpful. https://www.tinymce.com/docs/configure/integration-and-setup/#init_instance_callback wp_editor('', 'sedemoeditor', array( 'tinymce' => array( ...


0

the key "wp_capabilities" in table wp_usermeta identifies the serialized representation of an array that identifies a user's roles. The WordPress team named the field [prefix]_capabilities before they realized that "capabilities" were actually things grouped together for users filling a particular role. Changing the value of the key from ...


0

This ended up being a pretty significant problem with the function I hooked into editable_roles. The Goal: Allow Plugin Operators to add new Managers and New Employees Allow Plugin Managers to add new Employees The Problem: New users added by an Operator and/or a Manager were being saved with no role Operators/Managers could not modify the role of ...


2

You can use admin.php?action=my_action and WordPress will fire the equivalent action hook: // How to get the URL $url = admin_url( "admin.php?action=wpse_21460_export&any_other_arguments" ); // How to handle the URL function wpse_21460_export() { // Do your export and exit } add_action( 'admin_action_wpse_21460_export', 'wpse_21460_export' ); See ...


1

I believe you will need to add it via add_menu_page - but in the callback function you register that displays the page, you could re-direct away from it (or just display your own message), as needed. You could also remove it from showing up on the admin menu by calling remove_menu_page right after you add it. That ought to leave the page registered (with ...


1

It's what I thought - you're trying to send the file from the display callback, by which time it's too late. Look for the add_*_page() call that registers the menu item in the admin sidebar - the return value of this function call is the name of the hook you can use to attach the download function: $hook = add_submenu_page( $parent, $title, $menu_title, ...



Top 50 recent answers are included