# my-wp/1.5/controller/modules/mywp.controller.module.admin.posts.php

My WP Customize Admin/Frontend, version 1.5. 263 lines.

- Page: https://pluginprobe.com/plugins/my-wp/1.5/code/controller/modules/mywp.controller.module.admin.posts.php
- Raw: https://pluginprobe.com/plugins/my-wp/1.5/raw/controller/modules/mywp.controller.module.admin.posts.php
- Modified: 2017-08-28T09:57:00+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/my-wp/1.5/code/controller/modules/mywp.controller.module.admin.posts.php#L10-L20`.

```php
<?php

if ( ! defined( 'ABSPATH' ) ) {
  exit;
}

if( ! class_exists( 'MywpControllerAbstractModule' ) ) {
  return false;
}

if ( ! class_exists( 'MywpControllerModuleAdminPosts' ) ) :

final class MywpControllerModuleAdminPosts extends MywpControllerAbstractModule {

  static protected $id = 'admin_posts';

  static private $post_type = '';

  public static function mywp_controller_initial_data( $initial_data ) {

    $initial_data['bulk_post_updated_messages'] = array();

    $initial_data['per_page_num'] = '';
    $initial_data['hide_add_new'] = '';
    $initial_data['hide_search_box'] = '';

    return $initial_data;

  }

  public static function mywp_controller_default_data( $default_data ) {

    $default_data['bulk_post_updated_messages'] = array();

    $default_data['per_page_num'] = 20;
    $default_data['hide_add_new'] = false;
    $default_data['hide_search_box'] = false;

    return $default_data;

  }

  public static function get_bulk_update_messages_default() {

    $bulk_update_messages_default = array(
      'updated' => _n( '%s post updated.', '%s posts updated.', 0 ),
      'locked' => _n( '%s post not updated, somebody is editing it.', '%s posts not updated, somebody is editing them.', 0 ),
      'deleted' => _n( '%s post permanently deleted.', '%s posts permanently deleted.', 0 ),
      'trashed' => _n( '%s post moved to the Trash.', '%s posts moved to the Trash.', 0 ),
      'untrashed' => _n( '%s post restored from the Trash.', '%s posts restored from the Trash.', 0 ),
    );

    return $bulk_update_messages_default;

  }

  public static function mywp_wp_loaded() {

    if( ! is_admin() ) {

      return false;

    }

    if( is_network_admin() ) {

      return false;

    }

    if( ! self::is_do_controller() ) {

      return false;

    }

    add_action( 'mywp_ajax' , array( __CLASS__ , 'mywp_ajax' ) , 1000 );

    add_action( 'load-edit.php' , array( __CLASS__ , 'load_edit' ) , 1000 );

  }

  public static function mywp_get_option_key( $option_key ) {

    if( empty( self::$post_type ) ) {

      return $option_key;

    }

    $option_key .= '_' . self::$post_type;

    return $option_key;

  }

  public static function mywp_ajax() {

    if( empty( $_POST['action'] ) or $_POST['action'] != 'inline-save' ) {

      return false;

    }

    if( empty( $_POST['screen'] ) or $_POST['screen'] != 'edit-post' ) {

      return false;

    }

    if( empty( $_POST['post_type'] ) ) {

      return false;

    }

    self::$post_type = strip_tags( $_POST['post_type'] );

    add_filter( 'mywp_get_option_key_mywp_admin_posts' , array( __CLASS__ , 'mywp_get_option_key' ) );

  }

  public static function load_edit() {

    global $typenow;

    if( empty( $typenow ) ) {

      return false;

    }

    self::$post_type = $typenow;

    add_filter( 'mywp_get_option_key_mywp_admin_posts' , array( __CLASS__ , 'mywp_get_option_key' ) );

    add_filter( 'bulk_post_updated_messages' , array( __CLASS__ , 'change_bulk_post_updated_messages' ) );

    add_action( 'admin_print_styles' , array( __CLASS__ , 'hide_add_new' ) );

    add_action( 'admin_print_styles' , array( __CLASS__ , 'hide_search_box' ) );

    add_filter( "edit_{$typenow}_per_page" , array( __CLASS__ , 'edit_per_page' ) );

  }

  public static function change_bulk_post_updated_messages( $bulk_post_updated_messages ) {

    if( ! self::is_do_function( __FUNCTION__ ) ) {

      return $bulk_post_updated_messages;

    }

    $setting_data = self::get_setting_data();

    if( empty( $setting_data['bulk_post_updated_messages'] ) ) {

      return $bulk_post_updated_messages;

    }

    $bulk_post_updated_messages_default = self::get_bulk_update_messages_default();

    foreach( $bulk_post_updated_messages_default as $key => $v ) {

      if( ! empty( $setting_data['bulk_post_updated_messages'][ $key ] ) ) {

        $bulk_post_updated_messages[ self::$post_type ][ $key ] = $setting_data['bulk_post_updated_messages'][ $key ];

      }

    }

    self::after_do_function( __FUNCTION__ );

    return $bulk_post_updated_messages;

  }

  public static function hide_add_new() {

    if( ! self::is_do_function( __FUNCTION__ ) ) {

      return false;

    }

    $setting_data = self::get_setting_data();

    if( empty( $setting_data['hide_add_new'] ) ) {

      return false;

    }

    echo '<style>';

    echo 'body.wp-admin .wrap h1 a { display: none; }';
    echo 'body.wp-admin .wrap .page-title-action { display: none; }';

    echo '</style>';

    self::after_do_function( __FUNCTION__ );

  }

  public static function hide_search_box() {

    if( ! self::is_do_function( __FUNCTION__ ) ) {

      return false;

    }

    $setting_data = self::get_setting_data();

    if( empty( $setting_data['hide_search_box'] ) ) {

      return false;

    }

    echo '<style>';

    echo 'body.wp-admin #posts-filter .search-box { display: none; }';

    echo '</style>';

    self::after_do_function( __FUNCTION__ );

  }

  public static function edit_per_page( $per_page ) {

    if( ! self::is_do_function( __FUNCTION__ ) ) {

      return $per_page;

    }

    $setting_data = self::get_setting_data();

    if( empty( $setting_data['per_page_num'] ) ) {

      return $per_page;

    }

    $per_page = $setting_data['per_page_num'];

    self::after_do_function( __FUNCTION__ );

    return $per_page;

  }

}

MywpControllerModuleAdminPosts::init();

endif;

```
