Skip to content

Commit

Permalink
Merge branch 'settings'
Browse files Browse the repository at this point in the history
Conflicts:
	WPML_OptionsManager.php
  • Loading branch information
No3x committed Nov 22, 2014
2 parents 83540fa + eced53a commit 30971dd
Show file tree
Hide file tree
Showing 444 changed files with 55,852 additions and 188 deletions.
4 changes: 2 additions & 2 deletions WPML_Email_Log_List.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,8 @@ function process_bulk_action() {

//Detect when a bulk action is being triggered...
if( 'delete' == $this->current_action() ) {
foreach($_REQUEST[$name] as $item_id) {
$wpdb->query( "DELETE FROM `$tableName` WHERE mail_id = $item_id" );
foreach( $_REQUEST[$name] as $item_id) {
$wpdb->query( $wpdb->prepare("DELETE FROM `$tableName` WHERE `mail_id` = %d", $item_id) );
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion WPML_LifeCycle.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public function install() {

public function uninstall() {
$this->otherUninstall();
if( get_option( $this->prefix('DeleteOnDeactivation'), false) == 'true' ) {

if( $this->getSetting('delete-on-deactivation', false) == true ) {
//TOOD: is multi site?
$this->unInstallDatabaseTables();
$this->deleteSavedOptions();
Expand Down
241 changes: 88 additions & 153 deletions WPML_OptionsManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,26 @@
*/

class WPML_OptionsManager {

/**
* Is used to retrive a settings value
* Important: This implementation understands bool for $default. (unlikely in comparision to all other settings implementation)
* @since 1.4
* @param string $settingName The option name to return
* @param mixed $default (null) The value to return if option not set.
* @return Ambigous <string, mixed> the options value or $default if not found.
*/
public function getSetting($settingName, $default = null) {
global $wpml_settings;

if( key_exists($settingName, $wpml_settings)) {
$retVal = $wpml_settings[$settingName];
}
if (!isset($retVal) && $default !== null) {
$retVal = $default;
}
return $retVal;
}

public function getOptionNamePrefix() {
return get_class($this) . '_';
}
Expand Down Expand Up @@ -187,7 +206,7 @@ public function getRoleOption($optionName) {
* @return string a WP capability or '' if unknown input role
*/
protected function roleToCapability($roleName) {
switch ($roleName) {
switch ( $roleName ) {
case 'Super Admin':
return 'manage_options';
case 'Administrator':
Expand Down Expand Up @@ -242,32 +261,50 @@ public function createSettingsMenu() {
$pluginIcon = '';
if ( $wp_version >= 3.8 ) $pluginIcon = 'dashicons-email-alt';

$pluginName = $this->getPluginDisplayName();
$pluginNameSlug = strtolower( get_class($this) );
//create new top-level menu
$wp_logging_list_page = add_menu_page(__('WP Mail Log', 'wpml'),
__('WP Mail Log', 'wpml'),
'administrator',
get_class($this) . '_log',
$pluginNameSlug . '_log',
array(&$this, 'LogMenu'),
$pluginIcon
);

// Add Action to load assets when page is loaded
add_action( 'load-' . $wp_logging_list_page, array( $this, 'load_assets' ) );

//call register settings function
add_action('admin_init', array(&$this, 'registerSettings'));

add_submenu_page(get_class($this) . '_log',
__('Settings', 'wpml'),
__('Settings', 'wpml'),
'administrator',
get_class($this) . '_settings',
array(&$this, 'LogSubMenuSettings') );

add_action( 'contextual_help', array( &$this, 'create_settings_panel' ), 10, 3 );
add_submenu_page($pluginNameSlug . '_log',
__('About', 'wpml'),
__('About', 'wpml'),
'administrator',
$pluginNameSlug . '_about',
array(&$this, 'LogSubMenuAbout') );

add_action( 'contextual_help', array( &$this, 'create_settings_panel' ), 10, 3 );
}

public function LogSubMenuAbout() {
?>
<div class="wrap">
<h2><?php echo $this->getPluginDisplayName(); echo ' '; _e('About', 'wpml'); ?></h2>
<h3>Why use?</h3>
<p>Sometimes you may ask yourself if a mail was actually sent by WordPress - with
<strong>With <?php echo $this->getPluginDisplayName(); ?>, you can:</strong></p>
<ul>
<li>View a complete list of sent mails.</li>
<li>Search for mails.</li>
<li>Count on regular updates, enhancements, and troubleshooting.</li>
<li>Developer: Boost your development performance by keeping track of sent mails from your WordPress site.</li>
<li>Developer: Use Filters that are provided to extend the columns.</li>
</ul>
<h3>Donate</h3>
<p>Please consider to make a donation if you like the plugin. I spent a lot of time for support, enhancements and updates in general.</p>
<a title="Donate" href="http://no3x.de/web/donate">Donate</a>
</div>
<?php
}

public function load_assets() {

global $wp_logging_list_page;
Expand All @@ -283,14 +320,6 @@ public function load_assets() {

}

public function registerSettings() {
$settingsGroup = get_class($this) . '-settings-group';
$optionMetaData = $this->getOptionMetaData();
foreach ($optionMetaData as $aOptionKey => $aOptionMeta) {
register_setting($settingsGroup, $aOptionMeta);
}
}

/**
* Add settings Panel
*/
Expand Down Expand Up @@ -363,10 +392,9 @@ function save_screen_options( $status, $option, $value ) {
}

public function LogMenu() {

global $wp_version;

if (!current_user_can('manage_options')) {
if ( !current_user_can( $this->getSetting( 'can-see-submission-data', 'manage_options' ) ) ) {
wp_die(__('You do not have sufficient permissions to access this page.', 'wpml'));
}

Expand All @@ -377,145 +405,52 @@ public function LogMenu() {
?>
<div class="wrap">
<h2><?php echo $this->getPluginDisplayName(); echo ' '; _e('Log', 'wpml'); ?></h2>

<div id="wp-mail-logging-modal-wrap">
<div id="wp-mail-logging-modal-backdrop"></div>
<div id="wp-mail-logging-modal-content-wrap">
<div id="wp-mail-logging-modal-content">
<div id="wp-mail-logging-modal-content-header">
<a id="wp-mail-logging-modal-content-header-close" class="wp-mail-logging-modal-close" href="#" title="Close">
<?php if ( $wp_version >= 3.8 ): ?>
<div class="dashicons dashicons-no"></div>
<?php else: ?>
<span class="wp-mail-logging-modal-content-header-compat-close">X</span>
<?php endif; ?>
</a>
<?php
$emailLoggingListTable = new Email_Logging_ListTable();
$emailLoggingListTable->prepare_items();
?>

<div id="wp-mail-logging-modal-wrap">
<div id="wp-mail-logging-modal-backdrop"></div>
<div id="wp-mail-logging-modal-content-wrap">
<div id="wp-mail-logging-modal-content">
<div id="wp-mail-logging-modal-content-header">
<a id="wp-mail-logging-modal-content-header-close" class="wp-mail-logging-modal-close" href="#" title="Close">
<?php if ( $wp_version >= 3.8 ): ?>
<div id="wp-mail-logging-modal-content-header-icon" class="dashicons dashicons-email-alt"></div>
<div class="dashicons dashicons-no"></div>
<?php else: ?>
<span class="wp-mail-logging-modal-content-header-compat-close">X</span>
<?php endif; ?>
<div id="wp-mail-logging-modal-content-header-title">
<?php _e( 'Message', 'wpml' ); ?>
</div>
</a>
<?php if ( $wp_version >= 3.8 ): ?>
<div id="wp-mail-logging-modal-content-header-icon" class="dashicons dashicons-email-alt"></div>
<?php endif; ?>
<div id="wp-mail-logging-modal-content-header-title">
<?php _e( 'Message', 'wpml' ); ?>
</div>
<div id="wp-mail-logging-modal-content-body">
<div id="wp-mail-logging-modal-content-body-content">
</div>
<div id="wp-mail-logging-modal-content-body">
<div id="wp-mail-logging-modal-content-body-content">

</div>
</div>
<div id="wp-mail-logging-modal-content-footer">
<a class="wp-mail-logging-modal-close button button-primary" href="#"><?php _e( 'Close', 'wpml' ); ?></a>
</div>
</div>
<div id="wp-mail-logging-modal-content-footer">
<a class="wp-mail-logging-modal-close button button-primary" href="#"><?php _e( 'Close', 'wpml' ); ?></a>
</div>
</div>
</div>

<form id="email-list" method="get">
<input type="hidden" name="page" value="<?php echo $_REQUEST['page'] ?>" />

<?php
$search = ( isset( $_REQUEST['s'] ) ) ? $_REQUEST['s'] : false;
$emailLoggingListTable = new Email_Logging_ListTable();
$emailLoggingListTable->prepare_items( $search );
$emailLoggingListTable->search_box( __( 'Search' ), 's' );
$emailLoggingListTable->display();
?>
</form>


</div>

<form id="email-list" method="get">
<input type="hidden" name="page" value="<?php echo $_REQUEST['page'] ?>" />
<?php
$emailLoggingListTable->display();
?>
</form>
</div>
<?php
}

/**
* Creates HTML for the Administration page to set options for this plugin.
* Override this method to create a customized page.
* @return void
*/
public function LogSubMenuSettings() {
if (!current_user_can('manage_options')) {
wp_die(__('You do not have sufficient permissions to access this page.', 'wpml'));
}

$optionMetaData = $this->getOptionMetaData();

// Save Posted Options
if ($optionMetaData != null) {
foreach ($optionMetaData as $aOptionKey => $aOptionMeta) {
if (isset($_POST[$aOptionKey])) {
$this->updateOption($aOptionKey, $_POST[$aOptionKey]);
}
}
}

// HTML for the page
$settingsGroup = get_class($this) . '-settings-group';
?>
<div class="wrap">

<h2><?php echo $this->getPluginDisplayName(); echo ' '; _e('Settings', 'wpml'); ?></h2>

<form method="post" action="">
<?php settings_fields($settingsGroup); ?>
<table class="form-table"><tbody>
<?php
if ($optionMetaData != null) {
foreach ($optionMetaData as $aOptionKey => $aOptionMeta) {
$displayText = is_array($aOptionMeta) ? $aOptionMeta[0] : $aOptionMeta;
?>
<tr valign="top">
<th scope="row"><p><label for="<?php echo $aOptionKey ?>"><?php echo $displayText ?></label></p></th>
<td>
<?php $this->createFormControl($aOptionKey, $aOptionMeta, $this->getOption($aOptionKey)); ?>
</td>
</tr>
<?php
}
}
?>
</tbody></table>
<p class="submit">
<input type="submit" class="button-primary"
value="<?php _e('Save Changes', 'wpml') ?>"/>
</p>
</form>
</div>
<?php

}

/**
* Helper-function outputs the correct form element (input tag, select tag) for the given item
* @param $aOptionKey string name of the option (un-prefixed)
* @param $aOptionMeta mixed meta-data for $aOptionKey (either a string display-name or an array(display-name, option1, option2, ...)
* @param $savedOptionValue string current value for $aOptionKey
* @return void
*/
protected function createFormControl($aOptionKey, $aOptionMeta, $savedOptionValue) {
if (is_array($aOptionMeta) && count($aOptionMeta) >= 2) { // Drop-down list
$choices = array_slice($aOptionMeta, 1);
?>
<p><select name="<?php echo $aOptionKey ?>" id="<?php echo $aOptionKey ?>">
<?php
foreach ($choices as $aChoice) {
$selected = ($aChoice == $savedOptionValue) ? 'selected' : '';
?>
<option value="<?php echo $aChoice ?>" <?php echo $selected ?>><?php echo $this->getOptionValueI18nString($aChoice) ?></option>
<?php
}
?>
</select></p>
<?php

}
else { // Simple input field
?>
<p><input type="text" name="<?php echo $aOptionKey ?>" id="<?php echo $aOptionKey ?>"
value="<?php echo esc_attr($savedOptionValue) ?>" size="50"/></p>
<?php

}
}

/**
* Override this method and follow its format.
* The purpose of this method is to provide i18n display strings for the values of options.
Expand Down
33 changes: 1 addition & 32 deletions WPML_Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,6 @@ public static function getTablename( $name ) {
return $wpdb->prefix . 'wpml_' . $name;
}

/**
* See: http://plugin.michael-simpson.com/?page_id=31
* @return array of option meta data.
*/
public function getOptionMetaData() {
// http://plugin.michael-simpson.com/?page_id=31
return array(
//'_version' => array('Installed Version'), // Leave this one commented-out. Uncomment to test upgrades.
//'ATextInput' => array(__('Enter in some text', 'wml')),
'DeleteOnDeactivation' => array(__('Delete all data on deactivation? (emails and settings)', 'wml'), 'false', 'true'),
'CanSeeSubmitData' => array(__('Can See Submission data', 'wml'),
'Administrator', 'Editor', 'Author', 'Contributor', 'Subscriber', 'Anyone')
);
}

// protected function getOptionValueI18nString($optionValue) {
// $i18nValue = parent::getOptionValueI18nString($optionValue);
// return $i18nValue;
// }

protected function initOptions() {
$options = $this->getOptionMetaData();
if (!empty($options)) {
foreach ($options as $key => $arr) {
if (is_array($arr) && count($arr > 1)) {
$this->addOption($key, $arr[1]);
}
}
}
}

public function getPluginDisplayName() {
return 'WP Mail Logging';
}
Expand Down Expand Up @@ -128,7 +97,7 @@ public function addActionsAndFilters() {

// Add options administration page
// http://plugin.michael-simpson.com/?page_id=47
add_action( 'admin_menu', array(&$this, 'createSettingsMenu') );
add_action( 'admin_menu', array(&$this, 'createSettingsMenu'), 9 );

// Example adding a script & style just for the options administration page
// http://plugin.michael-simpson.com/?page_id=47
Expand Down
18 changes: 18 additions & 0 deletions inc/redux/admin-init.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

// Load the TGM init if it exists
if (file_exists(dirname(__FILE__).'/tgm/tgm-init.php')) {
require_once( dirname(__FILE__).'/tgm/tgm-init.php' );
}
// Load Redux extensions - MUST be loaded before your options are set
if (file_exists(dirname(__FILE__).'/redux-extensions/extensions-init.php')) {
require_once( dirname(__FILE__).'/redux-extensions/extensions-init.php' );
}
// Load the embedded Redux Framework
if (file_exists(dirname(__FILE__).'/redux-framework/ReduxCore/framework.php')) {
require_once( dirname(__FILE__).'/redux-framework/ReduxCore/framework.php' );
}
// Load the theme/plugin options
if (file_exists(dirname(__FILE__).'/options-init.php')) {
require_once( dirname(__FILE__).'/options-init.php' );
}
Loading

0 comments on commit 30971dd

Please sign in to comment.