Skip to content

Instantly share code, notes, and snippets.

@danielpataki
Last active August 29, 2015 14:08
Show Gist options
  • Save danielpataki/23c3001fe145a2def5a0 to your computer and use it in GitHub Desktop.
Save danielpataki/23c3001fe145a2def5a0 to your computer and use it in GitHub Desktop.
Common WordPress Code Mistakes
function user_edit_script( $hook ) {
if ( 'profile.php' != $hook ) {
return;
}
wp_enqueue_script( 'my-user-edit', plugin_dir_url( __FILE__ ) . 'js/my-user-edit.js' );
}
add_action( 'admin_enqueue_scripts', 'user_edit_script' );
add_action( 'wp_enqueue_scripts', 'enqueue_child_theme_styles', PHP_INT_MAX );
function enqueue_child_theme_styles() {
wp_enqueue_style( 'parent-style', get_template_directory_uri().'/style.css' );
wp_enqueue_style( 'child-style', get_stylesheet_uri(), array('parent-style') );
}
if( !function_exists( 'show_default_logo' ) ) {
function show_default_logo() {
echo '<img src="' . get_stylesheet_directory_uri() . '/images/logo.png" alt="Website Logo">';
}
}
/*
Theme Name: Twenty Fourteen Child
Theme URI: http://example.com/twenty-fourteen-child/
Description: Twenty Fourteen Child Theme
Author: John Doe
Author URI: http://example.com
Template: twentyfourteen
Version: 1.0.0
Tags: light, dark, two-columns, right-sidebar, responsive-layout, accessibility-ready
Text Domain: twenty-fourteen-child
*/
function my_frontend_styles() {
wp_enqueue_style( 'my-google-fonts', '//fonts.googleapis.com/css?family=Droid+Serif:400,700|Roboto+Condensed:400,700' );
}
add_action( 'wp_enqueue_scripts', 'my_styles' );
function my_admin_styles() {
wp_enqueue_style( 'my-google-fonts', '//fonts.googleapis.com/css?family=Droid+Serif:400,700|Roboto+Condensed:400,700' );
}
add_action( 'admin_enqueue_scripts', 'my_admin_styles' );
function user_edit_script( $hook ) {
$screen = get_current_screen();
if( 'post' == $screen->base && 'page' == $screen->post_type ) {
wp_enqueue_script( 'my-user-edit', plugin_dir_url( __FILE__ ) . 'js/my-user-edit.js' );
}
}
add_action( 'admin_enqueue_scripts', 'user_edit_script' );
$posts = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_type = 'post' AND post_status='publish' ORDER BY post_date DESC " );
$posts = new WP_Query( array(
'post_type' => 'post',
'post_status' => 'publish',
'fields' => 'ids'
));
add_action( 'plugins_loaded', 'myplugin_load_textdomain' );
function myplugin_load_textdomain() {
load_plugin_textdomain( 'my-plugin', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' );
}
$panel = array(
'panel_color' => 'ff9900',
'panel_position' => 'left',
'panel_size' => 'large'
);
add_option( 'my_plugin_panel_options', $plugin_options, '', 'no' );
$plugin_options = array(
'selected_color' => 'ff9900',
'favourite_post' => 11,
'favourite_shape' => 'icosahedron',
);
add_option( 'my_plugin_options', $plugin_options );
add_action( 'wp_enqueue_scripts', 'my_styles' );
function my_frontend_styles() {
wp_register_style( 'my-slider', get_template_directory_uri() . '/css/shortcode-slider.css' );
}
add_shortcode( 'my_slider', 'my_slider_display' );
function my_slider_display( $atts ) {
wp_enqueue_style( 'my-slider' );
// Code for the slider here
}
<?php _e( 'Populat Posts', 'mytextdomain' ) ?>
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
exit;
}
delete_option( 'my_plugin_options' );
delete_option( 'my_plugin_panel_options' );
$wpdb->query( "DELETE FROM $wpdb->postmeta WHERE meta_key = 'my_plugin_data' " );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment