-
Notifications
You must be signed in to change notification settings - Fork 383
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #714 from Automattic/amedina/amp-analytics-customizer
Enable adding AMP Analytics components using the Options API
- Loading branch information
Showing
16 changed files
with
641 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
require_once( AMP__DIR__ . '/includes/options/views/class-amp-analytics-options-submenu-page.php' ); | ||
require_once( AMP__DIR__ . '/includes/utils/class-amp-html-utils.php' ); | ||
|
||
class AMP_Analytics_Options_Submenu { | ||
|
||
private $parent_menu_slug; | ||
private $menu_slug; | ||
private $menu_page; | ||
|
||
public function __construct( $parent_menu_slug ) { | ||
$this->parent_menu_slug = $parent_menu_slug; | ||
$this->menu_slug = 'amp-analytics-options'; | ||
$this->menu_page = new AMP_Analytics_Options_Submenu_Page(); | ||
} | ||
|
||
public function init() { | ||
$this->add_submenu(); | ||
add_action( | ||
'admin_print_styles-amp_page_' . $this->menu_slug, | ||
array( $this, 'amp_options_styles' ) | ||
); | ||
} | ||
|
||
private function add_submenu() { | ||
add_submenu_page( | ||
$this->parent_menu_slug, | ||
__( 'AMP Analytics Options', 'amp' ), | ||
__( 'Analytics', 'amp' ), | ||
'manage_options', | ||
$this->menu_slug, | ||
array( $this->menu_page, 'render' ) | ||
); | ||
} | ||
|
||
public function amp_options_styles() { | ||
?> | ||
<style> | ||
.analytics-data-container #delete { | ||
background: red; | ||
border-color: red; | ||
text-shadow: 0 0 0; | ||
margin: 0 5px; | ||
} | ||
.amp-analytics-options.notice { | ||
width: 300px; | ||
} | ||
</style>; | ||
|
||
<?php | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
require_once( AMP__DIR__ . '/includes/options/class-amp-analytics-options-submenu.php' ); | ||
require_once( AMP__DIR__ . '/includes/options/views/class-amp-options-menu-page.php' ); | ||
require_once( AMP__DIR__ . '/includes/options/views/class-amp-options-manager.php' ); | ||
|
||
class AMP_Options_Menu { | ||
const ICON_BASE64_SVG = 'data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxvbmU9Im5vIj8+PHN2ZyB3aWR0aD0iNjJweCIgaGVpZ2h0PSI2MnB4IiB2aWV3Qm94PSIwIDAgNjIgNjIiIHZlcnNpb249IjEuMSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayI+ICAgICAgICA8dGl0bGU+QU1QLUJyYW5kLUJsYWNrLUljb248L3RpdGxlPiAgICA8ZGVzYz5DcmVhdGVkIHdpdGggU2tldGNoLjwvZGVzYz4gICAgPGRlZnM+PC9kZWZzPiAgICA8ZyBpZD0iYW1wLWxvZ28taW50ZXJuYWwtc2l0ZSIgc3Ryb2tlPSJub25lIiBzdHJva2Utd2lkdGg9IjEiIGZpbGw9Im5vbmUiIGZpbGwtcnVsZT0iZXZlbm9kZCI+ICAgICAgICA8ZyBpZD0iQU1QLUJyYW5kLUJsYWNrLUljb24iIGZpbGw9I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; | ||
|
||
private $menu_page; | ||
private $menu_slug; | ||
|
||
public function __construct() { | ||
$this->menu_page = new AMP_Options_Menu_Page(); | ||
$this->menu_slug = 'amp-plugin-options'; | ||
} | ||
|
||
public function init() { | ||
add_action( 'admin_post_amp_analytics_options', 'AMP_Options_Manager::handle_analytics_submit' ); | ||
|
||
add_action( 'admin_menu', array( $this, 'add_menu_items' ) ); | ||
} | ||
|
||
public function add_menu_items() { | ||
add_menu_page( | ||
__( 'AMP Options', 'amp' ), | ||
__( 'AMP', 'amp' ), | ||
'manage_options', | ||
$this->menu_slug, | ||
array( $this->menu_page, 'render' ), | ||
self::ICON_BASE64_SVG | ||
); | ||
|
||
$submenus = array( | ||
new AMP_Analytics_Options_Submenu( $this->menu_slug ), | ||
); | ||
|
||
// Create submenu items and calls on the Submenu Page object to render the actual contents of the page. | ||
foreach ( $submenus as $submenu ) { | ||
$submenu->init( $this->menu_slug ); | ||
} | ||
|
||
$this->remove_toplevel_menu_item(); | ||
} | ||
|
||
// Helper function to avoid having the top-level menu as | ||
// the first menu item | ||
function remove_toplevel_menu_item() { | ||
global $submenu; | ||
if ( isset( $submenu['amp-plugin-options'][0] ) ) { | ||
unset( $submenu['amp-plugin-options'][0] ); | ||
} | ||
} | ||
} |
Oops, something went wrong.