New answers tagged

2

That area of all admin screens is where admin notices are displayed, so you could generate an admin notice. Here's a suitable function and hook: function wpse_233031_admin_notice() { ?> <div class="notice notice-info"> <p>Your message here!</p> </div> <?php } function wpse_233031_hook_admin_notice() { ...


0

From WordPress 4.4 onwards, you can use the_post_thumbnail_url() inside The Loop to easily get the featured image source: <div style="background-image: url(<?php the_post_thumbnail_url(); ?>);"> //Your html code </div> If you need compatibility with releases prior to the 4.4, wp_get_attachment_image_src() will do the work. Contrary ...


0

If no role is checked when you submit, the $_POST['cat'] will not be set. That will trigger the "invalid argument supplied for foreach" error. In the beginning of your if ( isset($_POST['saveme']) ) structure, I'd put: if ( !isset($_POST['cat']) ) { // code to update db value to 0 }


11

We start by adding the custom TinyMCE Button: function add_mce_button_custom_em() { // check user permissions if ( !current_user_can( 'edit_posts' ) && !current_user_can( 'edit_pages' ) ) { return; } // check if WYSIWYG is enabled if ( 'true' == get_user_option( 'rich_editing' ) ) { add_filter( '...


1

You could try a plugin like Visual Editor Custom Buttons. Or you may want to do something custom. There's a solid example at http://code.tutsplus.com/tutorials/guide-to-creating-your-own-wordpress-editor-buttons--wp-30182.


0

your variable $roles , either contains no value or is not an array, foreach only process an array/object.


1

I am not confident without downloading Estonian copy of WP source, but from look at GlotPress it seems that locale code for it is simply et, not et_EE.


1

Sure. In your single.php or where you loop through the posts, start by getting the content: $content = get_the_content(); Then use a regex where you target anything within <h2> tags: $regex = '/<h2>(.*?)\<\/h2>/u'; And then use preg_match_all() to find all titles: preg_match_all($regex, $content, $table_of_content); This will ...


0

Solved. Problem was in copying theme's css file from an old to a new site. The "fa" icons changed from a graphical to a textual form in the css style. Thanks for help.


0

Check following thing into your site Please check that Font Awesome CSS is loading into page , you can check it using view page source, also need to check fonts folder is uploaded into all your sites , if you not upload fonts folder then it don't display icon.


0

When I realized that PHP is an acronym for "PHP Hypertext Preprocessor" -- emphasis on "preprocessor" -- I finally understood that I can't mix PHP and HTML and expect any kind of interactivity with the user. When a web page is served, the PHP creates the HTML and then the HTML is displayed by the browser. If the user does something the PHP must respond to, ...


0

It appears you are missing your plugin folder when enqueueing your scripts. plugins_url outputs the URL to your wp plugins folder it does not include your custom plugin folder. wp_register_script( 'script_js', plugins_url('/YOUR_FOLDER/js/script.js')); // Add your plugin folder wp_register_script( 'script_js', plugins_url('/js/script.js',__FILE__)); // Let ...


0

It's not clear to me what the "test" button is for, which I guess could make a difference, but, in general, I have found that to make two buttons work independently on the same options page, the easiest thing is to place them within two separately defined forms, even if the two buttons are going to be placed side by side. The simplest method is just to ...


3

From quick look WP seems to process array of theme data in a way that is used for both PHP and JS sides. Result passes through wp_prepare_themes_for_js filter, which seems like a suitable place to override screenshot URL as necessary. This worked in my dev install: add_filter( 'wp_prepare_themes_for_js', function ( $themes ) { $themes['r-test']['...


0

The solution is setting a function that’s hooked into init. add_action('init', 'stats_cookie'); function stats_cookie() { if(!isset($_COOKIE['site_stats'])) { $current = current_time( 'timestamp', 1); setcookie('site_stats', $current, time()+60+60*24*7, COOKIEPATH, COOKIE_DOMAIN ); } }


-1

To restrict the use of the shortcode on posts created by administrators only, I need to check if the post author of the post viewed is an administrator as shown in code if ( user_can( $post->post_author, 'activate_plugins' ) ). IF not, the content is returned without executing the do_shortcode($content) function. The current_user_can() function is not ...


0

Changing the comparison operator to == instead of strict comparison === as suggested by @czerspalace, solved the problem because on execution of my update function no rows were updated, so 0(int) was being returned . False is only returned if there is an error.


0

My WordPress install time setting was late by one hour, so all my database entries were expiring as soon as created. I corrected this by changing the time settings and now all is well


0

What you're looking for is called "pointers", available since 3.3 and you're right it lacks documentation. It's done with a little bit of JavaScript. You may look at this post to find useful information about pointers. It uses native WP scripts and styles this way : wp_enqueue_style( 'wp-pointer' ); wp_enqueue_script( 'wp-pointer' ); See also this ...


0

I am giving you an idea for this, you have to use jQuery for the popup and the below syntax will give you the current post data in a HTML popup. while ($the_query->have_posts()): $the_query->the_post(); echo '<div class="non-popup">'; echo '<div class="card-title" id="card-'.get_the_title.'">'.get_the_title().'</...


0

This is not possible at all. There aren't even duplication between page templates between the bundled themes. There is no way for you to know or to predict functions, outlay or markup in any template. IMHO, because of this, templates should always reside within a theme and not in a plugin. Afterall, templates are theme specific and not compatibable cross ...


0

You can use the native PHP sleep() function in WordPress for timers in seconds, or usleep() for timers in microseconds: http://php.net/manual/en/function.sleep.php http://php.net/manual/en/function.usleep.php


1

TomC is right, but to build on that here's what I do. Mainly I use this with a global object which I serialise into the session to save and unserialise from the session to use. Here I've just used an array of your variables. This way you don't need to worry about saving into the session as you go and the session use is easily expanded for other data. My ...


1

You want to use the init hook to start the session such as: function start_session() { if(!session_id()) { session_start(); } } add_action('init', 'start_session', 1); function end_session() { session_destroy (); } add_action('wp_logout', 'end_session'); add_action('wp_login', 'end_session'); This would go in the functions.php file. ...


0

You are using css to display none we don't need to use show() function. Please click on javascript icon in fiddle and select any jquery1.9.1 or above version . Update this code and run ( http://screenshotlink.ru/8f491216a33e437f762eb8815efec77d.png ) $(document).ready(function(){ $('.share-icon').on('click',function (e) { var id = $(this)....


-1

there are many ways to this but i suggest ajax for it. When you click on any post get the post_id and pass it to ajax function. Get id in ajax function(in function.php ) you called first and get post data. You can do two things on ajax sucess 1) append complete html( html for popup ) OR 2) just append thumbnail, title,excerpt values in html


0

As of WordPress 3.0.0 this action is available at the top of the new user form: user_new_form_tag As of WordPress 3.7.0 this action is called at the end of the form (right before submit button): user_new_form You will however need to intercept when clicking submit to save any specific user information to the user's meta


0

One simple solution is to check with the query string from the request: if ( !empty( $_REQUEST['action'] ) && "edit" == $_REQUEST['action'] ) { /* proceed */ } But it is also a good practice to use @mmm's suggestion since you are working with meta boxes where you have the $post object in use. When composing a new post, there's an automatically ...


0

Fatal error: Call to undefined function wp_get_current_user() This can be fixed by declaring check_user_role only when WP is ready, hooking into wp (to use WordPress functions and methods) or performing other workaround. Simply check if manage_options capability is there for the user too ( or verify if administrator is in the roles list in_array( "...


2

Now I got it! WordPress is just awesome. Also Thank you knif3r, your suggestions help me lot. I am trying to explain it in my words. Please correct me, if I am wrong. What is nonce? Nonce is something like security hash to prevent attacks and mistakes. It creates unique identifiers to check if the ajax request is coming from website or not. In WordPress ...


0

Here's what I did: Inserted ob_start() and ob_get_clean(), at strategic places in header.php and footer.php within a child theme derived from my base site's main theme. <some header stuff> ob_start() <header html I want to reuse across network> <?php $html = ob_get_clean(); echo $html; harvest_html($html, 'header'); ?> The function ...


1

Here is the process I follow. Step 1. specify the slug of the page you are putting the page on. To avoid hard coding this into the plugin, I add a setting option to store the slug of the page. So if I change the page, I only have to specify the slug of the new page in the settings page. function my_plugin_settings_page() { //Add a settings page for this ...


0

Your check of the php version is not in a separate function. That's the point that you not have the control about the order of the flow of this functions. The follow example source should get more clarity about the stack. The order is depend on the hooks in the plugintest_init function. You can also use the same hook and a different priority, the third ...


0

While what you used appears to work for now, I couldn't guarantee it isn't going to cause other issues now or in the future because - as you already know - tricking is_admin_bar_showing() isn't what the check of the XMLRPC_REQUEST constant was designed for. Therefore even if it doesn't cause issues now I don't think it would future-proof to use it like this. ...


0

Never mind, I just took a few hours away from the script and then I found the culprit... I did mistype the $proprietate variable when I assigned it to the db field (which is set to not NULL)...


0

Don't use double quotes (") inside the shortcode, since you are using double quotes to specify the href attribute. The browser thinks your href text ends at position=. Use single quotes instead: href="/reservation/?unitrate=[print_csv position='5']&amp;...I agree with the comments that there is a better way to do this, but I provide a potential answer ...


0

As @N00b said, if a selector matches between bootstrap and wordpress, and is more specific, then it will overwrite and you'll see the changes.


0

Close voting the question, but since it ill take time if it will even be deleted so here goes a more updated answer. Since the time the question was asked it seems like policy had been changed and few plugins ask for a permission to collect some "telemetry" information. I think that the main thing in getting such a plugin to be approved is for the user to ...


1

There are different approaches to this, depending on specific requirements. For example in your case you seem more worried about plugin picking up ghost data than that data being left behind. Such case might be easier handled by generating unique key prefix to use and just flushing that on uninstall. No prefix = no data access. I would say the general case ...


0

Yes, they should be, especially since cache might contain sensitive information the user might wish to be removed with the plugin. Best thing is to design your system in a way in which it is easy to delete all persistent information - for example place all your cache files under one directory. As for your example, cache in theory should not be part of an ...


0

function plugin_script() { wp_enqueue_script( 'Jquery-min', WP_PLUGIN_URL. '/Test Plugin/jquery-min.js', false, '1.11.0' );<br/> wp_enqueue_style('pluginstyle', WP_PLUGIN_URL. '/Test Plugin/pluginstyle.css',false,'1.0',"all");<br/> } add_action( 'wp_head', 'plugin_script' ); The "wp_head" action hook is triggered within the "head" ...


1

Anything outside the <?php ?> tags will be echoed as output since it has no conditions. The fastest way is to wrap in a function and output in the footer. add_action('wp_footer','custom_random_script'); function custom_random_script() { echo '<script> ......SCRIPT CONTENTS...... </script>'; } There is nothing technically ...


2

First of all there is no such thing as Wordpress Database in this context. You can use Wordpress with MySQL/MariaDB. You can use MySQL/MariaDB that wordpress uses to store your data. The size of your data is not a problem. The performance is not so straightforward to decide. I think MySQL will come close or better in most of the time. Also you will not be ...


2

Put the plugin in the wp-content/mu-plugins directory. Each site in your network has its own _options table in the database so as long as you are using built-in WP functions for handling your plugin's options, each site will have its own distinct set of options.


2

$callback = NULL means there is the $callback variable but it has no the value. In this case, unless you add any setting fields by add_setting_field() and register those settings by register_setting(), you'll get the Settings subheader on the Settings page without any content in this section. Here is an old tutorial which can be useful to show what I'm ...


2

I don't think the name (typeahead bundle) may contain spaces.


1

Is the plugin_method() publicly available? Check whether it is a class method or belongs to a namespace. If it belongs to a class, then you have to create an object of the class before you can call the method. Similarly if it is a namespace method, then you have to call the function with the full namespace.


1

Can you show full code in your unit tests bootstrap file? I am guessing the plugin would not be loaded properly, here is how it can be loaded as a mu-plugin when running tests. Anyway, I would suggest you to use WP CLI's command wp scaffold plugin-tests to get started with tests quickly documented here.


-1

Get all woocommerce product and its details like sku,price,product name $sql = "SELECT * FROM `wp_posts` wp LEFT JOIN wp_postmeta wpm ON wp.ID=wpm.post_id WHERE post_type='product'"; $results = $wpdb->get_results($sql); print_r($results);


0

Since wordpress 4.5 you can add inline script by wp_add_inline_script(). To add a javascript snippet to the footer that requires jQuery, this code helps you function enqueue_jquery_in_footer( &$scripts ) { if ( ! is_admin() ) $scripts->add_data( 'jquery', 'group', 1 ); } add_action( 'wp_default_scripts', 'enqueue_jquery_in_footer' ); ...



Top 50 recent answers are included