Tag Info

New answers tagged

0

TL;DR: After the draft_to_publish hook is executed, the page is redirected, so you won't see the echoed output. Ref: http://wordpress.stackexchange.com/a/94011/71131 I think the problem is that the draft_to_publish action saves the post, which will call a redirect request to the browser, which loads the edit page from scratch again. Then whatever whatever ...


0

That looks like it is an error due to TinyMCE (editorremov I believe) not being loaded yet. Either hook to the admin_footer action instead of admin_head (interestingly you have declared the in_footer option as true and it is still not working) or declare the editorremov dependency when enqueuing your script: wp_enqueue_script( 'features', plugin_dir_url( ...


0

Use the admin-post action hook to intercept POST requests and process forms. The admin_url() function can be used to output the correct URL, and use wp_redirect() to redirect back to your plugin page after processing. And do yourself and your users a favor- don't reinvent wheels and add tables when the native tables and API can be used.


-1

Try to simply use ob in your function like so: add_action( 'draft_to_publish', 'my_hooked_function', 10, 10 ); function my_hooked_function( $post ) { ob_start(); echo '<script>console.log("some stuff to output to the developer console, via html page");</script>'; $output = ob_get_contents(); // Put ob content in a variable ...


4

Wait for the action plugins_loaded before you create the class instance. The pluggable functions are loaded at this time. From wp-settings.php: /** * Fires once activated plugins have loaded. * * Pluggable functions are also available at this point in the loading order. * * @since 1.5.0 */ do_action( 'plugins_loaded' ); I would even wait for ...


1

The simplest and quickest solution would be to use the add_rewrite_endpoint function. <?php add_rewrite_endpoint( $name, $places ); ?> So in your case it would be something like this: add_rewrite_endpoint( 'user', EP_PERMALINK | EP_PAGES ); An user URL would look like this: http://www.example.com/my-page/user/john To access the variable: ...


0

You are missing 2 parameters in your function report_spam. Also the priority should not be 1. Try the code below. add_action('transition_comment_status', 'report_spam', 10, 3); function report_spam($new_status, $old_status, $comment){ if($new_status == 'spam'){ var_dump($comment->comment_author_IP); die; } } I've set die so ...


0

If you don't want to use the Dashboard Widgets API you can use this code snippet that I have quickly concocted as a starting point: function dashboard_daily_post_metabox() { add_meta_box( 'wt_id', 'Daily Post', 'dashboard_daily_post_process', 'dashboard', 'normal', 'high' ); } add_action( 'wp_dashboard_setup', 'dashboard_daily_post_metabox' ); ...


0

You should run your register_activation_hook after creating object. class Notification { function jal_install() { global $wpdb; global $jal_db_version; $table_name = $wpdb->prefix . 'fnotice'; $charset_collate = $wpdb->get_charset_collate(); $sql = "CREATE TABLE ...


2

You have misspelled the action hook name. This: add_action( 'after-setup_theme', 'ja_theme_setup' ); Should be: add_action( 'after_setup_theme', 'ja_theme_setup' ); The full code: add_action( 'after_setup_theme', 'ja_theme_setup' ); function ja_theme_setup() { add_theme_support( 'post-thumbnails'); }


-1

You need to go your wp-admin/post/ top right corner show "screen Options" click on this and expand screen-option then click on Featured Image check box Hope this help you..


-1

Your code should work , but as it is not working the try the following things add_theme_support( 'post-thumbnails'); Just put this code in functions.php , not within a function . Just put this code on the top of your functions.php file . If it is not working then try this plugin Drag & Drop Featured Image


0

After trying everything, this worked for me: global $allowedposttags; $allowedposttags['div'] = array('align' => array (), 'class' => array (), 'id' => array (), 'dir' => array (), 'lang' => array(), 'style' => array (), 'xml:lang' => array() ); $allowedposttags['iframe'] = array('src' => array () ); ...


0

This is not a casual task, nor do I think will you be able to find a free plugin to do that for you. How are your PHP skills? If not so much (and based on the casual way you've asked the question) I'm assuming they are zero, you will need to write up a specification for what you want, then pay a developer to create the product for you.


1

You are saving data to an option named my_option_name so your attempt to retrieve data from an option named $this->options['title'] isn't going to work. You will need something like this: public function DataToget($field = '') { if (empty($field)) return; $jugHigh = get_option( 'my_option_name' ); if (!isset($jugHigh[$field])) return; return ...


0

You misunderstand what page_template does. It does not create a new template that you will "show up" somewhere and that you can use. It replaces the page.php template provided by the theme. I think that what you want is template_redirect: function custom_page_template( $page_template ) { if (is_home()) { get_header(); echo 'do stuff'; ...


0

Its there you just need to click on "screen options" and make sure the checkbox is checked


0

The hook to use here is admin_notices. However in register_activation_hook and register_deactivation_hook it shouldn't be used because these function run when plugin activates and deactivates instance. A workaround it we use add_option when plugin activates and delete_option when plugin deactivates. Here is the code. Hopefully you will understand it ...


1

prepare accepts three placeholder arguments-- " %s (string), %d (integer) and %f (float)". You have used %i. That isn't going to get through the sanitization process. That is why you are getting 0. You need %d instead.


0

Could the same functionality be achieved with Transients? i.e.: set_transient( 'username', $_POST['firstname'], MINUTE_IN_SECONDS ); Sessions are not necessary then.


0

You can use like this, shortcode inside the Class class stockData{ function __construct() { add_shortcode( 'your_shortcode_name', array( $this, 'showData' ) ); //add_action('login_enqueue_scripts', array( $this,'my_admin_head')); } function showData(){ return '<h1>My shortcode content</h1>' ; } } ...


1

@s_ha_dum is correct that get_template_part is a theme function, but he is incorrect that plugins are not intended to be extended in this way. It is simply more complicated. This post by Pippin, describes how to use a function that will do the work of loading your plugin templates, while allowing users to override your plugin templates within their theme . ...


2

You should use pre_update_option_{option_name} filter. Example:- function system_save_number( $new_value, $old_value ) { mail('my@email.com','here',print_r($old_value ,true) . "\n\n" . print_r($new_value,true)); return $new_value; } function system_init_actions() { add_filter( 'pre_update_option_system_number', 'system_save_number', 10, 2 ); } ...


1

I pretty sure this filter lets you add an array of variables. I've not tested this: function add_custom_query_vars( $vars ){ $vars[] = "variable1"; $vars[] = "variable2"; $vars[] = "variable3"; //... etc return $vars; } add_filter( 'query_vars', 'add_custom_query_vars' ); Or another way of doing it would be to do this: function ...


2

This returns the current plugin's directory's server path: plugin_dir_path(__FILE__) // example: /home/myserver/public_html/wordpress_install/wp-content/plugins/exampleplugin/ Ref: https://codex.wordpress.org/Function_Reference/plugin_dir_path Not to be confused with: plugins_dir_path(__FILE__) (Notice the plural "plugins" on that.) Since you don't ...


0

I have cracked it. :) Here is my solution. add_rewrite_rule('^(property-details)/([^/]*)/?', 'index.php?pagename=$matches[1]&propertyidtag=$matches[2]','top'); add_filter('query_vars', 'foo_my_query_vars'); function foo_my_query_vars($vars){ $vars[] = 'propertyidtag'; return $vars; } Thank you for your help


2

Before I start, you should never ever use extract(). It is unreliable, and extremely hard to debug when it fails. For this specific reasons, it was (almost) completely removed from core and the codex. For more complete details, see trac ticket 22400. Along with query_posts, these are the two most commonly used and two worst functions to use. Lets get back ...


0

Reading and writing to a file is going to be dicey. You are going to be fighting with file permissions if you save anywhere but the wp-content/uploads directory (and it looks like you want to save to the plugins directory). If you have sufficient control of the server, you may get this to work by editing permissions in the plugins directory, but I wouldn't. ...


0

Here is one example I did for quick eidt add_action( 'quick_edit_custom_box', 'ks_add_to_bulk_quick_edit_custom_box', 10, 2 ); function ks_add_to_bulk_quick_edit_custom_box( $column_name, $post_type ) { switch ( $post_type ) { case 'post': switch( $column_name ) { case 'my_post_active': ?><fieldset ...


3

Your AJAX add_action and associated callback function shouldn't be inside view-create-rooms.php, move it into your main plugin file. When an AJAX request is sent, you're making a new separate request to the server, so your submenu page will not be loaded and your AJAX action never gets added to the queue.


0

At first glance it works and I cannot see any implications but maybe you are aware of some? You say that you are not getting errors, which I would have expected but it looks as though WordPress uses require_once() so you are probably safe: 39 /** WordPress Plugin Administration API */ 40 require_once(ABSPATH . 'wp-admin/includes/plugin.php'); ...


0

Per the discussion/help in this thread, below is the basic code that ended up working for my purposes. Setting the posts_per_page query var was a futile exercise since it is overwritten by the posts_per_rss option in a feed query (my scenario). posts_per_rss is not a query var and must be set a different way, thus the pre_option_posts_per_rss filter added. ...


1

Use Wordpress defult media uploader and get uploaded link in jquery response it is quit easy <label for="upload_image"> <input id="upload_image" type="text" size="36" name="ad_image" value="http://" /> <input id="upload_image_button" class="button" type="button" value="Upload Image" /> <br />Enter a URL or upload an ...


1

posts_per_rss is not a WP_Query parameter. It is the name of the option that is saved into the database. It can be addresses via the pre_option_{$option_name}: function wpse191824_posts_per_rss( $option_name ) { return 999; } add_filter( 'pre_option_posts_per_rss', 'wpse191824_posts_per_rss' );


0

First of all, you have to make sure to register your public query vars with WordPress so it recognizes your rewrite rule vars. Add this code on your functions.php file: add_rewrite_rule('^(tips)/([^/]*)/([^/]*)/?', 'index.php?name=$matches[1]&id=$matches[2]&filter_id=$matches[3]','top'); add_filter('query_vars', 'foo_my_query_vars'); function ...


1

The init hook runs well before pre_get_posts so dumping the query at that point-- on init-- isn't going to reflect anything that will be done much later. I don't think there is anything wrong with your code, you misunderstand the sequence of actions. What you expect to happen isn't what actually happens.


3

Could somebody explain why it's advised never to load wp-admin/admin.php in your plugin and how it could cause issues? Because it is loading WordPress out of context-- well, parts of WordPress. And that can cause unexpected effects such as functions not being loaded or functions being loaded twice (which will cause fatal errors). You will have trouble ...


1

You can do it, by using the proper filter inside the \WP_Screen class. Just make sure that you don't switch it on per default: How to show or hide the tab The following filter shows how to show or hide the tab. Actually, as there is a better filter, the following way is of more use if you need to force hide the tab when it already exists: add_filter( ...


2

I think this is what you are looking for . $cats = get_terms('category'); $blog_cats = array("all" => "All"); foreach ($cats as $cat) { $blog_cats[$cat->name] = $cat->name;} Then to show this <?php echo aq_field_select('category', $block_id, $blog_cats, $category); ?>


0

Question #1 - The above code will output 23123 twice, when visiting plugin page and when not. How do I make it print the content of my page only when page is the current screen? Basically: http://localhost/wp-admin/admin.php?page=camden-vmtool When you initialize the class, you are hooking the pageInit() method into a hook that fires on all admin ...


0

If you see the code, there is no hook to do that. But you can create your own function and remove the part that you don't need like this function custom_wp_install( $blog_title, $user_name, $user_email, $public, $deprecated = '', $user_password = '', $language = '' ) { if ( !empty( $deprecated ) ) _deprecated_argument( __FUNCTION__, '2.6' ); ...


1

As Rarst already noted, you answered your question. You are telling the software to load those scripts all the time. You need to control that process. Software is stupid. It can't decide when a good time is to load the code. SO... Since the plugin should only run when one of its shortcodes are called, ... Since you say the script should load only ...


0

You are answering your own question — scripts are being enqueued because that's what plugin does every load unconditionally. There is no logic that controls when should it happen or not happen, it simply happens always. If you take a closer look at a plugin that does it more intelligently you will usually notice one of these things: there are conditional ...


1

Use a PHP function to do this: https://php.net/strip_tags example: echo strip_tags("<div>my text</div>");


0

If it's only <div></div> I would do a preg_replace, like this: $string = preg_replace ( '|</?[^>]*>|i', '', $string ); This removes only the tags, not the text between the Tags. I understood this is what you wanted.


0

Just add frame: 'post', to wp.media attributes.


1

There is no action called wp_enqueue_script, it's wp_enqueue_scripts, plural, and both scripts and styles should be enqueued on that action.


1

Use this instead: Concatenate the html then return it. function check_my_login( $atts) { $html = '<form action="" name="" method="post" enctype="multipart/form-data">'; $html .= '<div class="form-group">'; $html .= '<label for="description">Project Description</label>'; $html .= '<textarea name="p_description" ...


0

The problem was not related at all with my plugin or with any kind of coding mistakes. When using W3 Total Cache the Database Cache seems to remove some data sent to functions, so the information about the username and password were not sent to the function causing the email to the user not to be sent (because there was no password given to the function) ...


1

Add this filter to functions.php file. Make your changes as needed. function display_my_content( $content ) { if ( is_single() ) { $the_content = 'Before your content'; $the_content .= $content; $the_content .= 'After your content'; return $the_content; } else { return $content; } } add_filter( ...



Top 50 recent answers are included