| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* admin side controller |
| 5 |
* accessible in $polylang global object |
| 6 |
* |
| 7 |
* properties: |
| 8 |
* options => inherited, reference to Polylang options array |
| 9 |
* model => inherited, reference to PLL_Model object |
| 10 |
* links_model => inherited, reference to PLL_Links_Model object |
| 11 |
* links => inherited, reference to PLL_Admin_Links object |
| 12 |
* static_pages => inherited, reference to PLL_Admin_Static_Pages object |
| 13 |
* filters_links => inherited, reference to PLL_Filters_Links object |
| 14 |
* curlang => inherited, optional, current language used to filter the content (language of the post or term being edited, equal to filter_lang otherwise) |
| 15 |
* filter_lang => inherited, optional, current status of the admin languages filter (in the admin bar) |
| 16 |
* pref_lang => inherited, preferred language used as default when saving posts or terms |
| 17 |
* filters => reference to PLL_Filters object |
| 18 |
* filters_columns => reference to PLL_Admin_Filters_Columns object |
| 19 |
* filters_post => reference to PLL_Admin_Filters_Post object |
| 20 |
* filters_term => reference to PLL_Admin_filters_Term object |
| 21 |
* nav_menu => reference to PLL_Admin_Nav_Menu object |
| 22 |
* filters_media => optional, reference to PLL_Admin_Filters_Media object |
| 23 |
* |
| 24 |
* @since 1.2 |
| 25 |
*/ |
| 26 |
class PLL_Admin extends PLL_Admin_Base { |
| 27 |
public $filters, $filters_columns, $filters_post, $filters_term, $nav_menu, $sync, $filters_media; |
| 28 |
|
| 29 |
/** |
| 30 |
* loads the polylang text domain |
| 31 |
* setups filters and action needed on all admin pages and on plugins page |
| 32 |
* |
| 33 |
* @since 1.2 |
| 34 |
* |
| 35 |
* @param object $links_model |
| 36 |
*/ |
| 37 |
public function __construct( &$links_model ) { |
| 38 |
parent::__construct( $links_model ); |
| 39 |
|
| 40 |
// adds a 'settings' link in the plugins table |
| 41 |
add_filter( 'plugin_action_links_' . POLYLANG_BASENAME, array( $this, 'plugin_action_links' ) ); |
| 42 |
add_action( 'in_plugin_update_message-' . POLYLANG_BASENAME, array( $this, 'plugin_update_message' ), 10, 2 ); |
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* setups filters and action needed on all admin pages and on plugins page |
| 47 |
* loads the settings pages or the filters base on the request |
| 48 |
* |
| 49 |
* @since 1.2 |
| 50 |
* |
| 51 |
* @param object $links_model |
| 52 |
*/ |
| 53 |
public function init() { |
| 54 |
parent::init(); |
| 55 |
|
| 56 |
// setup filters for admin pages |
| 57 |
// priority 5 to make sure filters are there before customize_register is fired |
| 58 |
if ( $this->model->get_languages_list() ) { |
| 59 |
add_action( 'wp_loaded', array( $this, 'add_filters' ), 5 ); |
| 60 |
} |
| 61 |
} |
| 62 |
|
| 63 |
/** |
| 64 |
* adds a 'settings' link in the plugins table |
| 65 |
* |
| 66 |
* @since 0.1 |
| 67 |
* |
| 68 |
* @param array $links list of links associated to the plugin |
| 69 |
* @return array modified list of links |
| 70 |
*/ |
| 71 |
public function plugin_action_links( $links ) { |
| 72 |
array_unshift( $links, '<a href="admin.php?page=mlang">' . __( 'Settings', 'polylang' ) . '</a>' ); |
| 73 |
return $links; |
| 74 |
} |
| 75 |
|
| 76 |
/** |
| 77 |
* adds the upgrade notice in plugins table |
| 78 |
* |
| 79 |
* @since 1.1.6 |
| 80 |
* |
| 81 |
* @param array $plugin_data not used |
| 82 |
* @param object $r plugin update data |
| 83 |
*/ |
| 84 |
function plugin_update_message( $plugin_data, $r ) { |
| 85 |
if ( isset( $r->upgrade_notice ) ) { |
| 86 |
printf( '<p style="margin: 3px 0 0 0; border-top: 1px solid #ddd; padding-top: 3px">%s</p>', esc_html( $r->upgrade_notice ) ); |
| 87 |
} |
| 88 |
} |
| 89 |
|
| 90 |
/** |
| 91 |
* setup filters for admin pages |
| 92 |
* |
| 93 |
* @since 1.2 |
| 94 |
*/ |
| 95 |
public function add_filters() { |
| 96 |
// all these are separated just for convenience and maintainability |
| 97 |
$classes = array( 'Filters', 'Filters_Columns', 'Filters_Post', 'Filters_Term', 'Nav_Menu', 'Sync' ); |
| 98 |
|
| 99 |
// don't load media filters if option is disabled or if user has no right |
| 100 |
if ( $this->options['media_support'] && ( $obj = get_post_type_object( 'attachment' ) ) && ( current_user_can( $obj->cap->edit_posts ) || current_user_can( $obj->cap->create_posts ) ) ) { |
| 101 |
$classes[] = 'Filters_Media'; |
| 102 |
} |
| 103 |
|
| 104 |
foreach ( $classes as $class ) { |
| 105 |
$obj = strtolower( $class ); |
| 106 |
|
| 107 |
/** |
| 108 |
* Filter the class to instantiate when loding admin filters |
| 109 |
* |
| 110 |
* @since 1.5 |
| 111 |
* |
| 112 |
* @param string $class class name |
| 113 |
*/ |
| 114 |
$class = apply_filters( 'pll_' . $obj, 'PLL_Admin_' . $class ); |
| 115 |
$this->$obj = new $class( $this ); |
| 116 |
} |
| 117 |
} |
| 118 |
} |
| 119 |
|