Last active
August 29, 2015 14:08
-
-
Save danielpataki/23c3001fe145a2def5a0 to your computer and use it in GitHub Desktop.
Common WordPress Code Mistakes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') ); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if( !function_exists( 'show_default_logo' ) ) { | |
function show_default_logo() { | |
echo '<img src="' . get_stylesheet_directory_uri() . '/images/logo.png" alt="Website Logo">'; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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 | |
*/ | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$posts = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE post_type = 'post' AND post_status='publish' ORDER BY post_date DESC " ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$posts = new WP_Query( array( | |
'post_type' => 'post', | |
'post_status' => 'publish', | |
'fields' => 'ids' | |
)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_action( 'plugins_loaded', 'myplugin_load_textdomain' ); | |
function myplugin_load_textdomain() { | |
load_plugin_textdomain( 'my-plugin', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' ); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$panel = array( | |
'panel_color' => 'ff9900', | |
'panel_position' => 'left', | |
'panel_size' => 'large' | |
); | |
add_option( 'my_plugin_panel_options', $plugin_options, '', 'no' ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$plugin_options = array( | |
'selected_color' => 'ff9900', | |
'favourite_post' => 11, | |
'favourite_shape' => 'icosahedron', | |
); | |
add_option( 'my_plugin_options', $plugin_options ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php _e( 'Populat Posts', 'mytextdomain' ) ?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) { | |
wp_enqueue_script( 'comment-reply' ); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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