Styles and Scripts, Selectively enqueue across entire site

Right I figured this out myself not sure how “hacky” this is but basically this is the code: public function filter_scripts_styles(){ if(is_page($this->plugin_name)){ //Same name is used for the style as the js file so can reuse this array $allowed = array(‘jquery’, $this->plugin_name.’_scrollpath’, $this->plugin_name); //Check Scripts First global $wp_scripts; foreach($wp_scripts->queue as $handle ) { if(!in_array($handle, $allowed)){ … Read more

Translate wordpress plugin [closed]

Do not create a PO file manually. The synchronization must be automatic, or you will waste much time. Each you change a string, you have to change it in two files now. Poedit has a built-in PHP parser. Use it to read your project files. And you don’t have to edit WPLANG to create a … Read more

Activating a single plugin via php

If you already have the plugin installed as part of the initial setup, you can add a loader for it in mu-plugins that activates it. Must-use plugins don’t require activation themselves, so adding a call to activate_plugin() inside it will attempt to automatically activate your plugin on every load. That becomes a problem if you … Read more

Subscribe2 Configuration

Sure it is joshau Thee S2 admin interface could be better, but it is stable, has been around a long time. You can exclude categories (eg all except your 2) and can allow users to select which categories they want from within that. I’m not the author, but I have it in use in a … Read more

Moving customized core code into plugins?

I’m under the assumption that WordPress will first look through all the functions in my plugins and if it finds one it won’t default to the WordPress core version of the function? No. Not counting any pluggable functions that might be added by a theme or plugin, the only functions that you can overwrite in … Read more

Get User ID from within a plugin

If you want current user id only then use get_current_user_id. because it reduce execution time. get_current_user_id get only current user id where wp_get_current_user get all user data. Else every things is perfect. $user_id = get_current_user_id(); $loc_statuss = $wpdb->get_row( “SELECT status FROM profile_location INNER JOIN relation_user ON profile_location.loc_id=relation_user.loc_id WHERE relation_user.user_id=”.$user_id ); $loc_status = $loc_statuss->status;

how to display all posts Custom fields dynamically?

<div class=”col-xs-12 col-sm-12 col-md-8 col-lg-8 left_column”> <?php if (have_posts()) : while (have_posts()) : the_post(); ?> <h1> <?php the_title();?> </h1> <?php $post_meta = get_post_meta(get_the_ID()); foreach($post_meta as $key=>$value) { echo “<strong>”.$key.”</strong>”.” => “; foreach($value as $nameAr=>$valueAr) { echo “<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;”; echo $nameAr.” => “.$valueAr; } echo “<br >”; } the_content(); endwhile; endif; ?> </div>

How to extract images of post and pages excluding header and logo image in wordpress?

I believe this will get you all of your attachments: $q = new WP_Query( array( ‘post_type’=>’attachment’, ‘post_status’=>’inherit’ ) ); var_dump($q); You could further restrict that by adding other parameters, for example, ‘post_mime_type’ => ‘image’ would restrict only to images. That will return all images though, not just the ones attached to posts. What you want … Read more

Dynamic homepage according to user role

To use a different page’s content on the homepage based on a logged-in user’s role you can do this: In your functions.php file add this code: function wpse_273872_pre_get_posts( $query ) { if ( $query->is_main_query() && is_user_logged_in() ) { //work-around for using is_front_page() in pre_get_posts //known bug in WP tracked by https://core.trac.wordpress.org/ticket/21790 $front_page_id = get_option(‘page_on_front’); $current_page_id … Read more