Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Customizing WordPress - Ioannis Karavas Software Engineer

Customizing WordPress - Ioannis Karavas Software Engineer

WordPress Greek Community

April 28, 2015
Tweet

More Decks by WordPress Greek Community

Other Decks in Technology

Transcript

  1. Filters Filters <?php add_filter( 'body_class', 'gimme_browser' ) ?> function gimme_browser($classes)

    { global $is_IE, $is_opera, $is_chrome, $is_iphone; if ($is_chrome) $classes[] = 'chrome'; elseif ($is_opera) $classes[] = 'opera'; ... return $classes; }
  2. Actions Actions add_action( 'user_register', 'handle_new_user' ); function handle_new_user($user_id) { $user_info

    = ... $new_post = array( 'post_name' => $user_name, ... 'post_excerpt' => '...', 'post_content' => 'Prompt user...' ); wp_insert_post( $new_post, $wp_error ); }
  3. Child Themes Child Themes function child_styles() { wp_enqueue_style( 'parent-style', get_template_directory_uri().'/style.css');

    } add_action( 'wp_enqueue_scripts', 'child_styles' ); functions.php is not overwritten!
  4. Roles & Capabilities Roles & Capabilities function restrict_editor() { $editorRole

    = get_role( 'editor' ); $capabilities = array( 'edit_others_posts', ... ); foreach ( $capabilities as $capability ) { $editorRole->remove_cap( $capability ); } } add_action( 'init', 'restrict_editor' );
  5. add_action( 'init', 'add_new_role' ); function add_new_role() { add_role( 'junior', __('Junior'),

    array( 'read' => true, 'edit_posts' => true, 'delete_posts' => false, ) ); } Roles & Capabilities Roles & Capabilities
  6. Custom Post Types Custom Post Types add_action( 'init', 'create_custom_post_type' );

    function create_custom_post_type() { register_post_type('projects', array( 'labels' => array( 'name' => __('Projects'), 'singular_name' => __('Projects'), ) ... ) ); }