Initial Commit
This commit is contained in:
parent
4c352bf02e
commit
1ab6e5f0b0
1085 changed files with 195258 additions and 0 deletions
|
@ -0,0 +1,109 @@
|
|||
<?php
|
||||
|
||||
// Shared logic between Jetpack admin pages
|
||||
abstract class Jetpack_Admin_Page {
|
||||
// Add page specific actions given the page hook
|
||||
abstract function add_page_actions( $hook );
|
||||
|
||||
// Create a menu item for the page and returns the hook
|
||||
abstract function get_page_hook();
|
||||
|
||||
// Enqueue and localize page specific scripts
|
||||
abstract function page_admin_scripts();
|
||||
|
||||
// Render page specific HTML
|
||||
abstract function page_render();
|
||||
|
||||
function __construct() {
|
||||
$this->jetpack = Jetpack::init();
|
||||
}
|
||||
|
||||
function add_actions() {
|
||||
/**
|
||||
* Don't add in the modules page unless modules are available!
|
||||
*/
|
||||
if ( $this->dont_show_if_not_active && ! Jetpack::is_active() && ! Jetpack::is_development_mode() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Initialize menu item for the page in the admin
|
||||
$hook = $this->get_page_hook();
|
||||
|
||||
// Attach hooks common to all Jetpack admin pages based on the created
|
||||
// hook
|
||||
add_action( "load-$hook", array( $this, 'admin_help' ) );
|
||||
add_action( "load-$hook", array( $this, 'admin_page_load' ) );
|
||||
add_action( "admin_head-$hook", array( $this, 'admin_head' ) );
|
||||
|
||||
add_action( "admin_footer-$hook", array( $this, 'module_modal_js_template' ) );
|
||||
|
||||
add_action( "admin_print_styles-$hook", array( $this, 'admin_styles' ) );
|
||||
add_action( "admin_print_scripts-$hook", array( $this, 'admin_scripts' ) );
|
||||
|
||||
// Attach page specific actions in addition to the above
|
||||
$this->add_page_actions( $hook );
|
||||
}
|
||||
|
||||
function admin_head() {
|
||||
if ( isset( $_GET['configure'] ) && Jetpack::is_module( $_GET['configure'] ) && current_user_can( 'manage_options' ) ) {
|
||||
/**
|
||||
* Fires in the <head> of a particular Jetpack configuation page.
|
||||
*
|
||||
* The dynamic portion of the hook name, `$_GET['configure']`,
|
||||
* refers to the slug of module, such as 'stats', 'sso', etc.
|
||||
* A complete hook for the latter would be
|
||||
* 'jetpack_module_configuation_head_sso'.
|
||||
*
|
||||
* @since 3.0.0
|
||||
*/
|
||||
do_action( 'jetpack_module_configuration_head_' . $_GET['configure'] );
|
||||
}
|
||||
}
|
||||
|
||||
// Render the page with a common top and bottom part, and page specific
|
||||
// content
|
||||
function render() {
|
||||
$this->admin_page_top();
|
||||
$this->page_render();
|
||||
$this->admin_page_bottom();
|
||||
}
|
||||
|
||||
function admin_help() {
|
||||
$this->jetpack->admin_help();
|
||||
}
|
||||
|
||||
function admin_page_load() {
|
||||
// This is big. For the moment, just call the existing one.
|
||||
$this->jetpack->admin_page_load();
|
||||
}
|
||||
|
||||
// Load underscore template for the landing page and settings page modal
|
||||
function module_modal_js_template() {
|
||||
Jetpack::init()->load_view( 'admin/module-modal-template.php' );
|
||||
}
|
||||
|
||||
function admin_page_top() {
|
||||
include_once( JETPACK__PLUGIN_DIR . '_inc/header.php' );
|
||||
}
|
||||
|
||||
function admin_page_bottom() {
|
||||
include_once( JETPACK__PLUGIN_DIR . '_inc/footer.php' );
|
||||
}
|
||||
|
||||
// Add page specific scripts and jetpack stats for all menu pages
|
||||
function admin_scripts() {
|
||||
$this->page_admin_scripts(); // Delegate to inheriting class
|
||||
add_action( 'admin_footer', array( $this->jetpack, 'do_stats' ) );
|
||||
}
|
||||
|
||||
// Enqueue the Jetpack admin stylesheet
|
||||
function admin_styles() {
|
||||
$min = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
|
||||
|
||||
wp_enqueue_style( 'jetpack-google-fonts', '//fonts.googleapis.com/css?family=Open+Sans:400italic,400,700,600,800' );
|
||||
|
||||
wp_enqueue_style( 'jetpack-admin', plugins_url( "css/jetpack-admin{$min}.css", JETPACK__PLUGIN_FILE ), array( 'genericons' ), JETPACK__VERSION . '-20121016' );
|
||||
wp_style_add_data( 'jetpack-admin', 'rtl', 'replace' );
|
||||
wp_style_add_data( 'jetpack-admin', 'suffix', $min );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,299 @@
|
|||
<?php
|
||||
include_once( 'class.jetpack-admin-page.php' );
|
||||
|
||||
// Builds the landing page and its menu
|
||||
class Jetpack_Landing_Page extends Jetpack_Admin_Page {
|
||||
protected $dont_show_if_not_active = false;
|
||||
|
||||
function get_page_hook() {
|
||||
$title = _x( 'Jetpack', 'The menu item label', 'jetpack' );
|
||||
|
||||
list( $jetpack_version ) = explode( ':', Jetpack_Options::get_option( 'version' ) );
|
||||
if (
|
||||
$jetpack_version
|
||||
&&
|
||||
$jetpack_version != JETPACK__VERSION
|
||||
&&
|
||||
( $new_modules = Jetpack::get_default_modules( $jetpack_version, JETPACK__VERSION ) )
|
||||
&&
|
||||
is_array( $new_modules )
|
||||
&&
|
||||
( $new_modules_count = count( $new_modules ) )
|
||||
&&
|
||||
( Jetpack::is_active() || Jetpack::is_development_mode() )
|
||||
) {
|
||||
$new_count_i18n = number_format_i18n( $new_modules_count );
|
||||
$span_title = esc_attr( sprintf( _n( 'One New Jetpack Module', '%s New Jetpack Modules', $new_modules_count, 'jetpack' ), $new_count_i18n ) );
|
||||
$format = _x( 'Jetpack %s', 'The menu item label with a new module count as %s', 'jetpack' );
|
||||
$update_markup = "<span class='update-plugins count-{$new_modules_count}' title='$span_title'><span class='update-count'>$new_count_i18n</span></span>";
|
||||
$title = sprintf( $format, $update_markup );
|
||||
}
|
||||
|
||||
// Add the main admin Jetpack menu with possible information about new
|
||||
// modules
|
||||
add_menu_page( 'Jetpack', $title, 'jetpack_admin_page', 'jetpack', array( $this, 'render' ), 'div' );
|
||||
// also create the submenu
|
||||
return add_submenu_page( 'jetpack', $title, $title, 'jetpack_admin_page', 'jetpack' );
|
||||
}
|
||||
|
||||
function add_page_actions( $hook ) {
|
||||
// Add landing page specific underscore templates
|
||||
/**
|
||||
* Filters the js_templates callback value
|
||||
*
|
||||
* @since 3.6.0
|
||||
*
|
||||
* @param array array( $this, 'js_templates' ) js_templates callback.
|
||||
* @param string $hook Specific admin page.
|
||||
*/
|
||||
add_action( "admin_footer-$hook", apply_filters( 'jetpack_landing_page_js_templates_callback', array( $this, 'js_templates' ), $hook ) );
|
||||
/** This action is documented in class.jetpack.php */
|
||||
do_action( 'jetpack_admin_menu', $hook );
|
||||
|
||||
// Place the Jetpack menu item on top and others in the order they
|
||||
// appear
|
||||
add_filter( 'custom_menu_order', '__return_true' );
|
||||
add_filter( 'menu_order', array( $this, 'jetpack_menu_order' ) );
|
||||
|
||||
add_action( 'jetpack_notices_update_settings', array( $this, 'show_notices_update_settings' ), 10, 1 );
|
||||
}
|
||||
|
||||
/*
|
||||
* Build an array of a specific module tag.
|
||||
*
|
||||
* @param string Name of the module tag
|
||||
* @return array The module slug, config url, and name of each Jump Start module
|
||||
*/
|
||||
function jumpstart_module_tag( $tag ) {
|
||||
$modules = Jetpack_Admin::init()->get_modules();
|
||||
|
||||
$module_info = array();
|
||||
foreach ( $modules as $module => $value ) {
|
||||
if ( in_array( $tag, $value['feature'] ) ) {
|
||||
$module_info[] = array(
|
||||
'module_slug' => $value['module'],
|
||||
'module_name' => $value['name'],
|
||||
'configure_url' => $value['configure_url'],
|
||||
);
|
||||
}
|
||||
}
|
||||
return $module_info;
|
||||
}
|
||||
|
||||
/*
|
||||
* Only show Jump Start on first activation.
|
||||
* Any option 'jumpstart' other than 'new connection' will hide it.
|
||||
*
|
||||
* The option can be of 4 things, and will be stored as such:
|
||||
* new_connection : Brand new connection - Show
|
||||
* jumpstart_activated : Jump Start has been activated - dismiss
|
||||
* jetpack_action_taken: Manual activation of a module already happened - dismiss
|
||||
* jumpstart_dismissed : Manual dismissal of Jump Start - dismiss
|
||||
*
|
||||
* @return bool | show or hide
|
||||
*/
|
||||
function jetpack_show_jumpstart() {
|
||||
$jumpstart_option = Jetpack_Options::get_option( 'jumpstart' );
|
||||
|
||||
$hide_options = array(
|
||||
'jumpstart_activated',
|
||||
'jetpack_action_taken',
|
||||
'jumpstart_dismissed'
|
||||
);
|
||||
|
||||
if ( ! $jumpstart_option || in_array( $jumpstart_option, $hide_options ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* List of recommended modules for the Jump Start paragraph text.
|
||||
* Will only show up in the paragraph if they are not active.
|
||||
*
|
||||
* @return string | comma-separated recommended modules that are not active
|
||||
*/
|
||||
function jumpstart_list_modules() {
|
||||
$jumpstart_recommended = $this->jumpstart_module_tag( 'Jumpstart' );
|
||||
|
||||
$module_name = array();
|
||||
foreach ( $jumpstart_recommended as $module => $val ) {
|
||||
if ( ! Jetpack::is_module_active( $val['module_slug'] ) ) {
|
||||
$module_name[] = $val['module_name'];
|
||||
}
|
||||
}
|
||||
|
||||
return $module_name;
|
||||
}
|
||||
|
||||
function jetpack_menu_order( $menu_order ) {
|
||||
$jp_menu_order = array();
|
||||
|
||||
foreach ( $menu_order as $index => $item ) {
|
||||
if ( $item != 'jetpack' )
|
||||
$jp_menu_order[] = $item;
|
||||
|
||||
if ( $index == 0 )
|
||||
$jp_menu_order[] = 'jetpack';
|
||||
}
|
||||
|
||||
return $jp_menu_order;
|
||||
}
|
||||
|
||||
function js_templates() {
|
||||
Jetpack::init()->load_view( 'admin/landing-page-templates.php' );
|
||||
}
|
||||
|
||||
function page_render() {
|
||||
// Handle redirects to configuration pages
|
||||
if ( ! empty( $_GET['configure'] ) ) {
|
||||
return $this->render_nojs_configurable();
|
||||
}
|
||||
|
||||
global $current_user;
|
||||
|
||||
$is_connected = Jetpack::is_active();
|
||||
$user_token = Jetpack_Data::get_access_token( $current_user->ID );
|
||||
$is_user_connected = $user_token && ! is_wp_error( $user_token );
|
||||
$is_master_user = $current_user->ID == Jetpack_Options::get_option( 'master_user' );
|
||||
|
||||
if ( Jetpack::is_development_mode() ) {
|
||||
$is_connected = true;
|
||||
$is_user_connected = true;
|
||||
$is_master_user = false;
|
||||
}
|
||||
|
||||
// Set template data for the admin page template
|
||||
$data = array(
|
||||
'is_connected' => $is_connected,
|
||||
'is_user_connected' => $is_user_connected,
|
||||
'is_master_user' => $is_master_user,
|
||||
'show_jumpstart' => $this->jetpack_show_jumpstart(),
|
||||
'jumpstart_list' => $this->jumpstart_list_modules(),
|
||||
'recommended_list' => $this->jumpstart_module_tag( 'Recommended' ),
|
||||
);
|
||||
Jetpack::init()->load_view( 'admin/admin-page.php', $data );
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows a notice message to users after they save Module config settings
|
||||
* @param string $module_id
|
||||
* @return null
|
||||
*/
|
||||
function show_notices_update_settings( $module_id ) {
|
||||
$state = Jetpack::state( 'message' );
|
||||
|
||||
switch( $state ) {
|
||||
case 'module_activated' :
|
||||
if ( $module = Jetpack::get_module( Jetpack::state( 'module' ) ) ) {
|
||||
$message = sprintf( __( '<strong>%s Activated!</strong> You can change the setting of it here.', 'jetpack' ), $module['name'] );
|
||||
}
|
||||
break;
|
||||
case 'module_configured':
|
||||
$message = __( '<strong>Module settings were saved.</strong> ', 'jetpack' );
|
||||
break;
|
||||
case 'no_message' :
|
||||
break;
|
||||
}
|
||||
|
||||
if ( isset( $message ) ) {
|
||||
?>
|
||||
<div id="message" class="jetpack-message">
|
||||
<div class="squeezer">
|
||||
<h2><?php echo wp_kses( $message, array( 'strong' => array(), 'a' => array( 'href' => true ), 'br' => true ) ); ?></h2>
|
||||
<?php
|
||||
/**
|
||||
* Fires within the displayed message when a feature configuation is updated.
|
||||
*
|
||||
* This is a dynamic hook with `$module_id` being the slug of the module being updated.
|
||||
*
|
||||
* @since 3.4.0
|
||||
*/
|
||||
do_action( 'jetpack_notices_update_settings_' . $module_id ); ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
add_action( 'jetpack_notices', array( Jetpack::init(), 'admin_notices' ) );
|
||||
}
|
||||
|
||||
// Render the configuration page for the module if it exists and an error
|
||||
// screen if the module is not configurable
|
||||
function render_nojs_configurable() {
|
||||
echo '<div class="clouds-sm"></div>';
|
||||
echo '<div class="wrap configure-module">';
|
||||
|
||||
$module_name = preg_replace( '/[^\da-z\-]+/', '', $_GET['configure'] );
|
||||
if ( Jetpack::is_module( $module_name ) && current_user_can( 'jetpack_configure_modules' ) ) {
|
||||
Jetpack::admin_screen_configure_module( $module_name );
|
||||
} else {
|
||||
echo '<h2>' . esc_html__( 'Error, bad module.', 'jetpack' ) . '</h2>';
|
||||
}
|
||||
|
||||
echo '</div><!-- /wrap -->';
|
||||
}
|
||||
|
||||
/*
|
||||
* Build an array of Jump Start stats urls.
|
||||
* requires the build URL args passed as an array
|
||||
*
|
||||
* @param array $jumpstart_stats
|
||||
* @return (array) of built stats urls
|
||||
*/
|
||||
function build_jumpstart_stats_urls( $jumpstart_stats ) {
|
||||
$jumpstart_urls = array();
|
||||
|
||||
foreach ( $jumpstart_stats as $value) {
|
||||
$jumpstart_urls[$value] = Jetpack::build_stats_url( array( 'x_jetpack-jumpstart' => $value ) );
|
||||
}
|
||||
|
||||
return $jumpstart_urls;
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Build an array of NUX admin stats urls.
|
||||
* requires the build URL args passed as an array
|
||||
*
|
||||
* @param array $nux_admin_stats
|
||||
* @return (array) of built stats urls
|
||||
*/
|
||||
function build_nux_admin_stats_urls( $nux_admin_stats ) {
|
||||
$nux_admin_urls = array();
|
||||
|
||||
foreach ( $nux_admin_stats as $value) {
|
||||
$nux_admin_urls[ $value ] = Jetpack::build_stats_url( array( 'x_jetpack-nux' => $value ) );
|
||||
}
|
||||
|
||||
return $nux_admin_urls;
|
||||
|
||||
}
|
||||
|
||||
function page_admin_scripts() {
|
||||
// Enqueue jp.js and localize it
|
||||
wp_enqueue_script( 'jetpack-js', plugins_url( '_inc/jp.js', JETPACK__PLUGIN_FILE ),
|
||||
array( 'jquery', 'wp-util' ), JETPACK__VERSION . '-20121111' );
|
||||
wp_localize_script(
|
||||
'jetpack-js',
|
||||
'jetpackL10n',
|
||||
array(
|
||||
'ays_disconnect' => __( "This will deactivate all Jetpack modules.\nAre you sure you want to disconnect?", 'jetpack' ),
|
||||
'ays_unlink' => __( "This will prevent user-specific modules such as Publicize, Notifications and Post By Email from working.\nAre you sure you want to unlink?", 'jetpack' ),
|
||||
'ays_dismiss' => __( "This will deactivate Jetpack.\nAre you sure you want to deactivate Jetpack?", 'jetpack' ),
|
||||
'view_all_features' => __( 'View all Jetpack features', 'jetpack' ),
|
||||
'no_modules_found' => sprintf( __( 'Sorry, no modules were found for the search term "%s"', 'jetpack' ), '{term}' ),
|
||||
'modules' => Jetpack::get_translated_modules( array_values( Jetpack_Admin::init()->get_modules() ) ),
|
||||
'currentVersion' => JETPACK__VERSION,
|
||||
'ajaxurl' => admin_url( 'admin-ajax.php' ),
|
||||
'jumpstart_modules' => $this->jumpstart_module_tag( 'Jumpstart' ),
|
||||
'show_jumpstart' => $this->jetpack_show_jumpstart(),
|
||||
'activate_nonce' => wp_create_nonce( 'jetpack-jumpstart-nonce' ),
|
||||
'admin_nonce' => wp_create_nonce( 'jetpack-admin-nonce' ),
|
||||
'jumpstart_stats_urls' => $this->build_jumpstart_stats_urls( array( 'dismiss', 'jumpstarted', 'learnmore', 'viewed', 'manual' ) ),
|
||||
'admin_stats_urls' => $this->build_nux_admin_stats_urls( array( 'enabled', 'deactivated', 'learnmore' ) ),
|
||||
'site_url_manage' => Jetpack::build_raw_urls( get_site_url() ),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,187 @@
|
|||
<?php
|
||||
include_once( 'class.jetpack-admin-page.php' );
|
||||
include_once( JETPACK__PLUGIN_DIR . 'class.jetpack-modules-list-table.php' );
|
||||
|
||||
// Builds the My Jetpack page
|
||||
class Jetpack_My_Jetpack_Page extends Jetpack_Admin_Page {
|
||||
// Show the settings page only when Jetpack is connected or in dev mode
|
||||
protected $dont_show_if_not_active = true;
|
||||
function add_page_actions( $hook ) {} // There are no page specific actions to attach to the menu
|
||||
|
||||
// Adds the My Jetpack page, but hides it from the submenu
|
||||
function get_page_hook() {
|
||||
return add_submenu_page( null, __( 'My Jetpack', 'jetpack' ), __( 'My Jetpack', 'jetpack' ), 'jetpack_connect_user', 'my_jetpack', array( $this, 'render' ) );
|
||||
}
|
||||
|
||||
// Renders the view file
|
||||
function page_render() {
|
||||
Jetpack::init()->load_view( 'admin/my-jetpack-page.php' );
|
||||
|
||||
//My Jetpack view tracking, send to MC Stats
|
||||
Jetpack::init()->stat( 'admin', 'my-jetpack' );
|
||||
Jetpack::init()->do_stats( 'server_side' );
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* Handle the change in master user
|
||||
*/
|
||||
function jetpack_my_jetpack_change_user() {
|
||||
if ( ! isset( $_POST['_my_jetpack_nonce'] ) || ! wp_verify_nonce( $_POST['_my_jetpack_nonce'], 'jetpack_change_primary_user' ) ) {
|
||||
wp_die( __( 'Failed permissions, please try again.', 'jetpack' ) );
|
||||
exit;
|
||||
}
|
||||
|
||||
if ( isset( $_POST['jetpack-new-master'] ) ) {
|
||||
$old_master_user = Jetpack_Options::get_option( 'master_user' );
|
||||
$new_master_user = $_POST['jetpack-new-master'];
|
||||
$user_token = Jetpack_Data::get_access_token( $new_master_user );
|
||||
$is_user_connected = $user_token && ! is_wp_error( $user_token );
|
||||
if ( current_user_can( 'manage_options' ) && $is_user_connected ) {
|
||||
Jetpack::log( 'switch_master_user', array( 'old_master' => $old_master_user, 'new_master' => $new_master_user ) );
|
||||
Jetpack_Options::update_option( 'master_user', $new_master_user );
|
||||
Jetpack::state( 'message', 'switch_master' );
|
||||
|
||||
//My Jetpack primary user successfully changed, send to MC Stats
|
||||
Jetpack::init()->stat( 'admin', 'change-primary-successful' );
|
||||
Jetpack::init()->do_stats( 'server_side' );
|
||||
|
||||
// Change the blog owner dotcom side
|
||||
$this->wpcom_switch_blog_owner( $new_master_user );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Tell wpcom that the master user has switched
|
||||
* so we can update the 'wpcom_blog_owner'
|
||||
*/
|
||||
function wpcom_switch_blog_owner( $new_master ) {
|
||||
$request = array(
|
||||
'new_blog_owner' => $new_master
|
||||
);
|
||||
|
||||
// Tell wpcom about the change
|
||||
Jetpack::load_xml_rpc_client();
|
||||
$xml = new Jetpack_IXR_Client( array(
|
||||
'user_id' => get_current_user_id(),
|
||||
) );
|
||||
|
||||
$xml->query( 'jetpack.switchBlogOwner', $request );
|
||||
}
|
||||
|
||||
/*
|
||||
* Checks to see if there are any other users available to become primary
|
||||
* Users must both:
|
||||
* - Be linked to wpcom
|
||||
* - Be an admin
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function jetpack_are_other_users_linked_and_admin() {
|
||||
// If only one admin
|
||||
$all_users = count_users();
|
||||
if ( 2 > $all_users['avail_roles']['administrator'] ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$users = get_users();
|
||||
$available = array();
|
||||
// If no one else is linked to dotcom
|
||||
foreach ( $users as $user ) {
|
||||
if ( isset( $user->caps['administrator'] ) && Jetpack::is_user_connected( $user->ID ) ) {
|
||||
$available[] = $user->ID;
|
||||
}
|
||||
}
|
||||
|
||||
if ( 2 > count( $available ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* All the data we'll need about the Master User
|
||||
* for the My Jetpack page template
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function jetpack_master_user_data() {
|
||||
// If the master user has disappeared, none of this is useful.
|
||||
// @todo throw up a warning and offer a solution
|
||||
$master = Jetpack_Options::get_option( 'master_user' );
|
||||
if ( ! get_user_by( 'id', $master ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$master_user = get_userdata( $master );
|
||||
$master_user_data_com = Jetpack::get_connected_user_data( $master_user->ID );
|
||||
$gravatar = sprintf( '<a href="%s">%s</a>', get_edit_user_link( $master_user->ID ), get_avatar( $master_user->ID, 40 ) );
|
||||
|
||||
$master_user_data = array(
|
||||
'masterUser' => $master_user,
|
||||
'masterDataCom' => $master_user_data_com,
|
||||
'gravatar' => $gravatar,
|
||||
);
|
||||
|
||||
return $master_user_data;
|
||||
}
|
||||
|
||||
/*
|
||||
* All the data we'll need about the Current User
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function jetpack_current_user_data() {
|
||||
global $current_user;
|
||||
$is_master_user = $current_user->ID == Jetpack_Options::get_option( 'master_user' );
|
||||
$dotcom_data = Jetpack::get_connected_user_data();
|
||||
|
||||
$current_user_data = array(
|
||||
'isUserConnected' => Jetpack::is_user_connected( $current_user->ID ),
|
||||
'isMasterUser' => $is_master_user,
|
||||
'adminUsername' => $current_user->user_login,
|
||||
'userComData' => $dotcom_data,
|
||||
'gravatar' => sprintf( '<a href="%s">%s</a>', get_edit_user_link( $current_user->ID ), get_avatar( $current_user->ID, 40 ) ),
|
||||
);
|
||||
|
||||
return $current_user_data;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Build an array of My Jetpack stats urls.
|
||||
* requires the build URL args passed as an array
|
||||
*
|
||||
* @param array $my_jetpack_stats
|
||||
* @return (array) of built stats urls
|
||||
*/
|
||||
function build_my_jetpack_stats_urls( $my_jetpack_stats ) {
|
||||
$my_jetpack_urls = array();
|
||||
|
||||
foreach ( $my_jetpack_stats as $value ) {
|
||||
$my_jetpack_urls[ $value ] = Jetpack::build_stats_url( array( 'x_jetpack-admin' => $value ) );
|
||||
}
|
||||
|
||||
return $my_jetpack_urls;
|
||||
|
||||
}
|
||||
|
||||
// Load up admin scripts
|
||||
function page_admin_scripts() {
|
||||
wp_enqueue_script( 'jp-connection-js', plugins_url( '_inc/jp-my-jetpack.js', JETPACK__PLUGIN_FILE ), array( 'jquery', 'wp-util' ), JETPACK__VERSION . 'yep' );
|
||||
|
||||
wp_localize_script( 'jp-connection-js', 'jpConnection',
|
||||
array(
|
||||
'jetpackIsActive' => Jetpack::is_active(),
|
||||
'isAdmin' => current_user_can( 'jetpack_manage_modules' ),
|
||||
'otherAdminsLinked' => $this->jetpack_are_other_users_linked_and_admin(),
|
||||
'masterUser' => $this->jetpack_master_user_data(),
|
||||
'currentUser' => $this->jetpack_current_user_data(),
|
||||
'my_jetpack_stats_urls' => $this->build_my_jetpack_stats_urls( array( 'change_primary', 'disconnect_site', 'confirm_disconnect', 'support_no_disconnect', 'cancel_disconnect' ) ),
|
||||
'alertText' => __( 'You must link another admin account before switching primary account holders.', 'jetpack' ),
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,87 @@
|
|||
<?php
|
||||
include_once( 'class.jetpack-admin-page.php' );
|
||||
include_once( JETPACK__PLUGIN_DIR . 'class.jetpack-modules-list-table.php' );
|
||||
|
||||
// Builds the settings page and its menu
|
||||
class Jetpack_Settings_Page extends Jetpack_Admin_Page {
|
||||
// Show the settings page only when Jetpack is connected or in dev mode
|
||||
protected $dont_show_if_not_active = true;
|
||||
function add_page_actions( $hook ) {} // There are no page specific actions to attach to the menu
|
||||
|
||||
// Adds the Settings sub menu
|
||||
function get_page_hook() {
|
||||
return add_submenu_page( 'jetpack', __( 'Jetpack Settings', 'jetpack' ), __( 'Settings', 'jetpack' ), 'jetpack_manage_modules', 'jetpack_modules', array( $this, 'render' ) );
|
||||
}
|
||||
|
||||
// Renders the module list table where you can use bulk action or row
|
||||
// actions to activate/deactivate and configure modules
|
||||
function page_render() {
|
||||
$list_table = new Jetpack_Modules_List_Table;
|
||||
?>
|
||||
<div class="clouds-sm"></div>
|
||||
<?php /** This action is already documented in views/admin/admin-page.php */
|
||||
do_action( 'jetpack_notices' ) ?>
|
||||
<div class="page-content configure">
|
||||
<div class="frame top hide-if-no-js">
|
||||
<div class="wrap">
|
||||
<div class="manage-left">
|
||||
<table class="table table-bordered fixed-top">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="check-column"><input type="checkbox" class="checkall"></th>
|
||||
<th colspan="2">
|
||||
<?php $list_table->unprotected_display_tablenav( 'top' ); ?>
|
||||
<span class="filter-search">
|
||||
<button type="button" class="button">Filter</button>
|
||||
</span>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
</table>
|
||||
</div>
|
||||
</div><!-- /.wrap -->
|
||||
</div><!-- /.frame -->
|
||||
<div class="frame bottom">
|
||||
<div class="wrap">
|
||||
<div class="manage-right">
|
||||
<div class="bumper">
|
||||
<form class="navbar-form" role="search">
|
||||
<input type="hidden" name="page" value="jetpack_modules" />
|
||||
<?php $list_table->search_box( __( 'Search', 'jetpack' ), 'srch-term' ); ?>
|
||||
<p><?php esc_html_e( 'View:', 'jetpack' ); ?></p>
|
||||
<div class="button-group filter-active">
|
||||
<button type="button" class="button <?php if ( empty( $_GET['activated'] ) ) echo 'active'; ?>"><?php esc_html_e( 'All', 'jetpack' ); ?></button>
|
||||
<button type="button" class="button <?php if ( ! empty( $_GET['activated'] ) && 'true' == $_GET['activated'] ) echo 'active'; ?>" data-filter-by="activated" data-filter-value="true"><?php esc_html_e( 'Active', 'jetpack' ); ?></button>
|
||||
<button type="button" class="button <?php if ( ! empty( $_GET['activated'] ) && 'false' == $_GET['activated'] ) echo 'active'; ?>" data-filter-by="activated" data-filter-value="false"><?php esc_html_e( 'Inactive', 'jetpack' ); ?></button>
|
||||
</div>
|
||||
<p><?php esc_html_e( 'Sort by:', 'jetpack' ); ?></p>
|
||||
<div class="button-group sort">
|
||||
<button type="button" class="button <?php if ( empty( $_GET['sort_by'] ) ) echo 'active'; ?>" data-sort-by="name"><?php esc_html_e( 'Alphabetical', 'jetpack' ); ?></button>
|
||||
<button type="button" class="button <?php if ( ! empty( $_GET['sort_by'] ) && 'introduced' == $_GET['sort_by'] ) echo 'active'; ?>" data-sort-by="introduced" data-sort-order="reverse"><?php esc_html_e( 'Newest', 'jetpack' ); ?></button>
|
||||
<button type="button" class="button <?php if ( ! empty( $_GET['sort_by'] ) && 'sort' == $_GET['sort_by'] ) echo 'active'; ?>" data-sort-by="sort"><?php esc_html_e( 'Popular', 'jetpack' ); ?></button>
|
||||
</div>
|
||||
<p><?php esc_html_e( 'Show:', 'jetpack' ); ?></p>
|
||||
<?php $list_table->views(); ?>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
<div class="manage-left">
|
||||
<form class="jetpack-modules-list-table-form" onsubmit="return false;">
|
||||
<table class="<?php echo implode( ' ', $list_table->get_table_classes() ); ?>">
|
||||
<tbody id="the-list">
|
||||
<?php $list_table->display_rows_or_placeholder(); ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</form>
|
||||
</div>
|
||||
</div><!-- /.wrap -->
|
||||
</div><!-- /.frame -->
|
||||
</div><!-- /.content -->
|
||||
<?php
|
||||
}
|
||||
|
||||
// Javascript logic specific to the list table
|
||||
function page_admin_scripts() {
|
||||
wp_enqueue_script( 'jetpack-admin-js', plugins_url( '_inc/jetpack-admin.js', JETPACK__PLUGIN_FILE ), array( 'jquery' ), JETPACK__VERSION . '-20121111' );
|
||||
}
|
||||
}
|
Reference in a new issue