Skip to content

Instantly share code, notes, and snippets.

@davilera
Last active April 11, 2017 11:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davilera/76df4e5ec09e1691dc4438c01c6ad49c to your computer and use it in GitHub Desktop.
Save davilera/76df4e5ec09e1691dc4438c01c6ad49c to your computer and use it in GitHub Desktop.
Coding Standards WordPress

Examples for our post in Nelio Software.

<?php
/**
* Register the main hooks related to the admin area functionality of the plugin.
*
* @since 1.0.0
* @access private
*/
private function define_admin_hooks() {
// If the plugin is configured, we can load everything else.
$reference_post_type = Nelio_Content_Reference_Post_Type_Register::instance();
$reference_post_type->defineAdminHooks();
$pluginAdmin = new Nelio_Content_Admin( $this->get_plugin_name(), $this->get_version() );
add_action( 'wp_loaded', array( Nelio_Content_Settings::instance(), 'defineAdminHooks' ) );
add_action( 'wp_loaded', array( $pluginAdmin, 'add_admin_menus' ) );
$ncte = new nelio_content_tinymce_extensions();
$ncte->define_admin_hooks();
$aux = new NelioContentExternalFeaturedImageAdmin();
$aux->defineAdminHooks();
// ...
}//end define_admin_hooks()
<?php
if(!isset($users[$user_id])){
$users[$user_id] = $this->get_user_info($user_id,'lazy');
}//endif
$this->set_admin_user($user_id);
<?php
// ...
if ( ! isset( $users[ $user_id ] ) ) {
$users[ $user_id ] = $this->get_user_info( $user_id, 'lazy' );
}//endif
$this->set_admin_user( $user_id );
// ...
var users = loadUsers();
if ( 'undefined' !== typeof users[ userId ] ) {
users[ userId ] = loadUser( userId );
}//end if
<?php
if ( $length == 1 ) {
// Some action.
}//end if
<?php
if ( 1 == $length ) {
// Some action.
}//end if
<?php
if ( true == $the_force ) {
$victorious = you_will( $be );
}//end if
<?php
isset( $var ) || $var = some_function();
<?php
if ( ! isset( $var ) ) {
$var = some_function();
}//end if
<?php
public function register_menus() {
$menu_list = array();
// ...
}//end register_menus()
function addCustomButton() {
var customButton = new Button();
// ...
}//end addCustomButton()
<?php
public function enqueue_scripts() {
$post_type_object = $this->get_post_type_object();
wp_enqueue_script(
'nelio-content-script',
NELIO_CONTENT_ADMIN_URL . '/js/script.min.js',
array( 'jquery', 'underscore' ),
$this->get_version(),
true
);
wp_localize_script(
'nelio-content-script',
'NelioContentScript',
array(
'canUserPublishPosts' => current_user_can( $post_type_obj->cap->publish_posts ),
'canUserEditPublishedPosts' => current_user_can( $post_type_obj->cap->edit_published_posts ),
'i18n' => array(
'ok' => _x( 'OK', 'command', 'nelio-content' ),
'cancel' => _x( 'Cancel', 'command', 'nelio-content' ),
'save' => _x( 'Save', 'command', 'nelio-content' ),
'published' => _x( 'Published', 'text', 'nelio-content' ),
),
)
);
}//end enqueue_scripts()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment