check for the current screen

Those variables and functions only exist in the admin area, and aren’t for frontend use. You will need to use a different mechanism for the frontend. Additionally: the docs say that you have to call this after the admin_init hook, calling on that hook will always return null the function is not loaded on all … Read more

Calling function from within functions.php returns unwanted value

Inside this loop: foreach ( $attachments as $id => $attachment ) { $link = isset($attr[‘link’]) && ‘file’ == $attr[‘link’] ? wp_get_attachment_link($id, $size, false, false) : wp_get_attachment_link($id, $size, true, false); $output .= “<{$itemtag} class=”gallery-item”>”; $output .= “<span class=”photos-comment-number-wrap”><span class=”comment-number”>”. comments_number() .”</span></span>”; $output .= ” <{$icontag} class=”gallery-icon”> $link </{$icontag}>”; if ( $captiontag && trim($attachment->post_excerpt) ) { $output … Read more

Why does my hand-written plugin installer fail to find `request_filesystem_credentials`?

I forgot to include the files necessary for these functions to work. And so, here’s your dirty-quick way to install plugins: $plugin = THEME_DIR . ‘/Inc/Plugins/my-shortcodes.zip’; $options = array( ‘package’ => $plugin, ‘destination’ => WP_PLUGIN_DIR, ‘clear_destination’ => false, ‘clear_working’ => true, ‘is_multi’ => true, ‘hook_extra’ => array( ‘plugin’ => $plugin, ), ); require_once ABSPATH . … Read more

Trying to get logged-in user data inside php class

Once you said is you first time using OOP, I want to say: stop using & before $this: PHP4 died long time ago. Second tip, don’t use global variables, if you can. I know that function like wp_get_current_user use global variable internally, but I hope that in future it will not be so anymore, however … Read more

Deactivate plugins using Migrate DB’s find and replace options

To disable plugins using the find and replace option in Migrate DB, search for the file path to the plugins main PHP file, and replace it with nothing. To disable W3 Total Cache for example, you would search for w3-total-cache/w3-total-cache.php and leave the replace field empty. Explanation WordPress stores the active plugin data in the … Read more

Use touch_time() on front-end form via plugin

You might try to include the the template.php file: <?php if( ! function_exists( ‘touch_time’ ) ) { require_once( ABSPATH . ‘/wp-admin/includes/template.php’ ); touch_time( 0, 0, 5 ); } ?> but I think it might be better to just copy the code from the touch_time() function into your own function and modify accordingly. Friday part of … Read more

Change plugin’s has_archive = true to false?

The register_post_type_args filter (available from WordPress v4.4 on) will allow post type registration arguments to be changed: function wpse206329_custom_post_type_args( $args, $post_type ) { if ( $post_type === “my_post_type” ) { $args[‘rewrite’] = false; } return $args; } add_filter( ‘register_post_type_args’, ‘wpse206329_custom_post_type_args’, 20, 2 );

Get subcategories with JSON API plugin

Retrieving terms With the current version of the “WP API” (JSON API plugin), there’s a simple way to retrieve terms: GET /taxonomies/<taxonomy>/terms The method responsible is get_taxonomy_terms( $taxonomy ) in the plugins core. You will have to check is_wp_error() on the return value to check if the taxonomy exists at the point where you invoke … Read more