Global Objects and Public Methods

This is not common practice, but it works. A better approach, is to use a class and with the singleton pattern, just like WooCommerce and many others, where you have: A static function (called instance, getInstance…) that: Creates an instance (object) if not already done and returns it Or returns the existing instance Let’s continue … Read more

get_template_part from plugin

/** *Extend WP Core get_template_part() function to load files from the within Plugin directory defined by PLUGIN_DIR_PATH constant * * Load the page to be displayed * from within plugin files directory only * * @uses mec_locate_admin_menu_template() function * * @param $slug * @param null $name */ function mec_get_admin_menu_page($slug, $name = null) { do_action(“mec_get_admin_menu_page_{$slug}”, $slug, … Read more

Customizing the 3.5 “Add Media” popup (Backbone.js)

I had do adapt Backbone for a project of mine, so I might help to get you started. If you want to adapt the rendering of your Backbone Templates, you need to rewrite them, because there are no built in filters for existing Templates. add_action(‘print_media_templates’, ‘print_my_media_templates’); function print_my_media_templates() { ?> <script type=”text/html” id=”my-custom-template”> //TODO: Copy … Read more

Overide get_template_part( ‘partials/post’, ‘sidebar’ ); with a plugin

TL;DR: Use a child theme instead 🙂 If we dig into the code for get_template_part(), there’s an action there – get_template_part_{$slug} – which we could hook into. Digging a bit further, get_template_part() calls locate_template(), which calls load_template(). Unfortunately, there’s nothing in either of these functions that seems to be pluggable, so we can’t hook in … Read more

Add Dividers or Separators Between Nav Menu Items

Use a custom walker. Extend start_el() to print <li class=”menu_separator”><hr></li> if the menu title is just a ‘-‘. functions.php function wpse38241_setup_menu() { register_nav_menu( ‘main-menu’, ‘Main Menu’ ); } add_action( ‘after_setup_theme’, ‘wpse38241_setup_menu’ ); /** * Replaces items with ‘-‘ as title with li class=”menu_separator” * * @author Thomas Scholz (toscho) */ class Wpse38241_Separator_Walker extends Walker_Nav_Menu { … Read more

Scheduled events disappear from events queue

My solution for now is check every hour if it is running and if not reschedule it. I also remove this in deactivate etc. wp_schedule_event(time(), ‘hourly’, ‘my_restart_schedule_if_failed’); function my_restart_schedule_if_failed() { if( !wp_next_scheduled( ‘my_scheduled_minute_job’ ) ) { wp_schedule_event( time(), ‘one_minute’, ‘my_scheduled_minute_job’ ); } }

Widget development – Drop down options won’t save

Danny, this is pretty much lifted straight from a plug-in I’ve made: <?php function form($instance){ $instance = wp_parse_args( (array) $instance, $this->w_arg ); ?> <p> <select id=”<?php echo $this->get_field_id(‘order’); ?>” name=”<?php echo $this->get_field_name(‘order’); ?>” type=”text”> <option value=”asc” <?php selected($instance[‘order’], ‘asc’); ?>>ASC </option> <option value=”desc” <?php selected($instance[‘order’], ‘desc’);?>>DESC </option> </select> </p> <?php } ?> Without seeing the … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)