From 3159dbcde507737b25608d17e69e359a421d1abe Mon Sep 17 00:00:00 2001 From: Lena Stergatou Date: Tue, 29 Nov 2022 17:12:03 +0200 Subject: [PATCH 1/4] Update changelog.txt --- changelog.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/changelog.txt b/changelog.txt index ea28df2..9a2de12 100644 --- a/changelog.txt +++ b/changelog.txt @@ -2,6 +2,9 @@ == Changelog == += 1.0.8 = +* Fix minor bugs + = 1.0.7.7 = * Fix: PHP error : Trying to get property of non-object From 0f93c7f24ba73742abce9e6bbbd87d1d725722e2 Mon Sep 17 00:00:00 2001 From: Lena Stergatou Date: Tue, 29 Nov 2022 17:13:10 +0200 Subject: [PATCH 2/4] remove empty folder --- external/dash-notice | 1 - tips.php | 7 ------- 2 files changed, 8 deletions(-) delete mode 160000 external/dash-notice diff --git a/external/dash-notice b/external/dash-notice deleted file mode 160000 index bda258b..0000000 --- a/external/dash-notice +++ /dev/null @@ -1 +0,0 @@ -Subproject commit bda258bc46cbf9646bc8220c9b9a63856f0112e6 diff --git a/tips.php b/tips.php index 1096d67..20170fb 100644 --- a/tips.php +++ b/tips.php @@ -461,10 +461,3 @@ function tips_manage_output() { } echo ''; } - -/* - * Update Notifications Notice - */ -global $wpmudev_notices; -$wpmudev_notices[] = array( 'id'=> 61, 'name'=> 'Admin Panel Tips', 'screens' => array( 'settings_page_manage-tips-network', 'settings_page_manage-tips' ) ); -include_once(plugin_dir_path( __FILE__ ).'external/dash-notice/wpmudev-dash-notification.php'); \ No newline at end of file From 83d394baaa5c55508b8415efe7c651d78f1ff5ab Mon Sep 17 00:00:00 2001 From: Lena Stergatou Date: Tue, 29 Nov 2022 17:55:11 +0200 Subject: [PATCH 3/4] Add Settings page --- tips.php | 122 +++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 82 insertions(+), 40 deletions(-) diff --git a/tips.php b/tips.php index 20170fb..1bc9e36 100644 --- a/tips.php +++ b/tips.php @@ -4,7 +4,7 @@ Plugin URI: http://premium.wpmudev.org/project/admin-panel-tips/ Description: Provide your users with helpful random tips (or promotions/news) in their admin panels. Author: WPMU DEV -Version: 1.0.7.7 +Version: 1.0.8 Author URI: http://premium.wpmudev.org/ Network: true WDP ID: 61 @@ -30,6 +30,7 @@ define('TIPS_LANG_DOMAIN', 'tips'); + /* Get admin page location */ if ( is_multisite() ) { $tips_menu_slug = 'settings.php'; @@ -41,13 +42,14 @@ add_action('admin_menu', 'tips_plug_pages'); } -$tips_current_version = '1.0.7.7'; +global $tips_current_version; +$tips_current_version = '1.0.8'; $tmp_tips_prefix = ""; $tmp_tips_suffix = ""; register_activation_hook(__FILE__, 'tips_make_current'); -if (!isset($_GET['updated']) || !isset($_GET['activated']) || ($_GET['updated'] != 'true' && $_GET['activated'] != 'true')){ +if (!isset($_GET['updated']) || !isset($_GET['activated']) || ($_GET['updated'] != 'true' && $_GET['activated'] != 'true')) { add_action('admin_notices', 'tips_output'); //add_action('network_admin_notices', 'tips_output'); } @@ -82,35 +84,18 @@ function tips_enqueue_scripts() { } function tips_make_current() { - global $wpdb, $tips_current_version; - if (get_site_option( "tips_version" ) == '') { - add_site_option( 'tips_version', '0.0.0' ); - } - tips_global_install(); - if (get_site_option( "tips_version" ) == $tips_current_version) { - // do nothing - } else { - //update to current version - // update_site_option( "tips_installed", "no" ); - update_site_option( "tips_version", $tips_current_version ); - } - //--------------------------------------------------// - if (get_option( "tips_version" ) == '') { - add_option( 'tips_version', '0.0.0' ); - } - - if (get_option( "tips_version" ) == $tips_current_version) { + global $tips_current_version; + + if (get_site_option( "tips_version" ) === $tips_current_version) { // do nothing } else { + tips_global_install(); //update to current version - update_option( "tips_version", $tips_current_version ); - tips_blog_install(); + } } -function tips_blog_install() { - global $wpdb, $tips_current_version; -} + function tips_global_init() { if (preg_match('/mu\-plugin/', PLUGINDIR) > 0) { @@ -120,6 +105,13 @@ function tips_global_init() { } } +/** + * + * @global type $wpdb + * @global string $tips_current_version + * + * @version 2.0 + */ function tips_global_install() { global $wpdb, $tips_current_version; @@ -129,12 +121,12 @@ function tips_global_install() { if ( ! empty($wpdb->collate) ) $charset_collate .= " COLLATE $wpdb->collate"; - if (get_site_option( "tips_installed" ) == '') { + if (!(get_site_option( "tips_installed" ))) { add_site_option( 'tips_installed', 'no' ); } if (get_site_option( "tips_installed" ) == "yes") { - if ( version_compare("1.0.4", get_site_option( "tips_version" )) >= 0) { + if ( version_compare('1.0.4', get_site_option( "tips_version" )) >= 0) { $tips_table1 = "ALTER TABLE `" . $wpdb->base_prefix . "tips` ADD `tip_status` INT( 1 ) NOT NULL DEFAULT '1' AFTER `tip_added` ;"; $wpdb->query( $tips_table1 ); } @@ -146,23 +138,35 @@ function tips_global_install() { `tip_added` varchar(255), `tip_status` int(1) NOT NULL default '1', PRIMARY KEY (`tip_ID`) -) ENGINE=MyISAM {$charset_collate};"; - +) {$charset_collate};"; $wpdb->query( $tips_table1 ); update_site_option( "tips_installed", "yes" ); + update_site_option( "tips_version", $tips_current_version ); } } +/** + * + * @global type $tips_menu_slug + * @version 2.0 + */ function tips_plug_pages() { global $tips_menu_slug; - if (is_super_admin()) + if (is_super_admin()) { add_submenu_page( $tips_menu_slug, __('Tips', TIPS_LANG_DOMAIN), __('Tips', TIPS_LANG_DOMAIN), 'manage_options', 'manage-tips', 'tips_manage_output' ); + } } +/** + * + * @global type $user_id + * + * @version 2.0 + */ function tips_profile_option_update() { global $user_id; - if ( $_POST['show_tips'] != '' ) { + if ( '' !== $_POST['show_tips'] ) { update_user_meta($user_id, 'show_tips', $_POST['show_tips']); } } @@ -172,11 +176,13 @@ function tips_profile_option_update() { //------------------------------------------------------------------------// function tips_output() { - global $wpdb, $current_site, $tmp_tips_prefix, $tmp_tips_suffix, $current_user; + global $wpdb, $tmp_tips_prefix, $tmp_tips_suffix, $current_user; //hide if turned off $show_tips = get_user_meta($current_user->ID,'show_tips', true); - if ( 'no' == $show_tips ) return; + if ( 'no' === $show_tips ) { + return; + } $dismissed_tips = isset($_COOKIE['tips_dismissed'])?maybe_unserialize(stripslashes($_COOKIE['tips_dismissed'])):array(); @@ -250,8 +256,16 @@ function tips_profile_option_output() { //---Page Output Functions------------------------------------------------// //------------------------------------------------------------------------// +/** + * + * @global type $wpdb + * @global type $tips_admin_url + * @return type + * + * @version 2.0 + */ function tips_manage_output() { - global $wpdb, $wp_roles, $current_site, $tips_admin_url; + global $wpdb, $tips_admin_url; if(!current_user_can('manage_options')) { echo "

" . __('Nice Try...', TIPS_LANG_DOMAIN) . "

"; //If accessed properly, this message doesn't appear. @@ -299,16 +313,16 @@ function tips_manage_output() { echo ""; echo "" . $tmp_tip['tip_content'] . ""; echo "" . date_i18n(get_option('date_format') . ' ' . get_option('time_format'), $tmp_tip['tip_added']) . ""; - echo "" . (($tmp_tip['tip_status'] == 1)?__('Published', TIPS_LANG_DOMAIN):__('Draft', TIPS_LANG_DOMAIN)) . ""; + echo "" . ((1 === $tmp_tip['tip_status'] )?__('Published', TIPS_LANG_DOMAIN):__('Draft', TIPS_LANG_DOMAIN)) . ""; echo '" . __('Edit', TIPS_LANG_DOMAIN) . ""; echo '" . __('Remove', TIPS_LANG_DOMAIN) . ""; - if ($tmp_tip['tip_status'] == 1) { + if ( 1 === $tmp_tip['tip_status'] ) { echo '" . __('Un-publish', TIPS_LANG_DOMAIN) . ""; } else { echo '" . __('Publish', TIPS_LANG_DOMAIN) . ""; } echo ""; - $class = ('alternate' == $class) ? '' : 'alternate'; + $class = ('alternate' === $class) ? '' : 'alternate'; //=========================================================// } } @@ -344,7 +358,7 @@ function tips_manage_output() { break; //---------------------------------------------------// case "new_tip_process": - if ($_POST['tip_content'] == ''){ + if ( '' === $_POST['tip_content'] ){ ?>

@@ -405,7 +419,7 @@ function tips_manage_output() { case "edit_tip_process": $tmp_tip_count = $wpdb->get_var("SELECT COUNT(*) FROM " . $wpdb->base_prefix . "tips WHERE tip_ID = '" . $_POST['tid'] . "' AND tip_site_ID = '" . $wpdb->siteid . "'"); if ($tmp_tip_count > 0){ - if ($_POST['tip_content'] == ''){ + if ( '' === $_POST['tip_content'] ){ ?>

@@ -461,3 +475,31 @@ function tips_manage_output() { } echo ''; } + +/** + * Add settings link on plugin page + * @param type $links + * @param type $file + * @return array + * + * @since 1.0.8 + */ +function tips_settings_link( $links, $file ) { + if (is_multisite()) { + $location = 'settings.php'; + } + else { + $location = 'options-general.php'; + } + return array_merge( + $links, + array( + 'settings' => '' . esc_html__( 'Settings', 'bp-group-documents' ) . '', + ) + ); + +} + +/// Add link to settings page +add_filter( 'plugin_action_links_tips/tips.php', 'tips_settings_link', 10, 2 ); +add_filter( 'network_admin_plugin_action_links_tips/tips.php', 'tips_settings_link', 10, 2 ); From fae5a3164eaabf7b42a7ee0870bdf0b6a349efa4 Mon Sep 17 00:00:00 2001 From: Lena Stergatou Date: Mon, 12 Dec 2022 13:54:53 +0200 Subject: [PATCH 4/4] Update tips.php Fix some bugs --- tips.php | 464 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 238 insertions(+), 226 deletions(-) diff --git a/tips.php b/tips.php index 1bc9e36..e4ea460 100644 --- a/tips.php +++ b/tips.php @@ -1,7 +1,7 @@ ID, 'show_tips', 'no'); - wp_safe_redirect(wp_get_referer()); + + update_user_meta( $current_user->ID, 'show_tips', 'no' ); + wp_safe_redirect( wp_get_referer() ); exit(); } function tips_enqueue_scripts() { - wp_enqueue_script('jquery'); + wp_enqueue_script( 'jquery' ); } function tips_make_current() { - global $tips_current_version; - - if (get_site_option( "tips_version" ) === $tips_current_version) { - // do nothing - } else { - tips_global_install(); - //update to current version - - } + global $tips_current_version; + + if ( get_site_option( 'tips_version' ) === $tips_current_version ) { + // do nothing + } else { + tips_global_install(); + //update to current version + + } } function tips_global_init() { - if (preg_match('/mu\-plugin/', PLUGINDIR) > 0) { - load_muplugin_textdomain(TIPS_LANG_DOMAIN, false, dirname(plugin_basename(__FILE__)).'/languages'); + if ( preg_match( '/mu\-plugin/', PLUGINDIR ) > 0 ) { + load_muplugin_textdomain( 'tips', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' ); } else { - load_plugin_textdomain(TIPS_LANG_DOMAIN, false, dirname(plugin_basename(__FILE__)).'/languages'); + load_plugin_textdomain( 'tips', false, dirname( plugin_basename( __FILE__ ) ) . '/languages' ); } } /** - * + * * @global type $wpdb * @global string $tips_current_version - * + * * @version 2.0 */ function tips_global_install() { global $wpdb, $tips_current_version; - + // Get the correct character collate - if ( ! empty($wpdb->charset) ) + if ( ! empty( $wpdb->charset ) ) { $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset"; - if ( ! empty($wpdb->collate) ) + } + if ( ! empty( $wpdb->collate ) ) { $charset_collate .= " COLLATE $wpdb->collate"; - - if (!(get_site_option( "tips_installed" ))) { + } + + if ( ! ( get_site_option( 'tips_installed' ) ) ) { add_site_option( 'tips_installed', 'no' ); } - - if (get_site_option( "tips_installed" ) == "yes") { - if ( version_compare('1.0.4', get_site_option( "tips_version" )) >= 0) { - $tips_table1 = "ALTER TABLE `" . $wpdb->base_prefix . "tips` ADD `tip_status` INT( 1 ) NOT NULL DEFAULT '1' AFTER `tip_added` ;"; - $wpdb->query( $tips_table1 ); + + if ( 'yes' === get_site_option( 'tips_installed' ) ) { + if ( version_compare( '1.0.4', get_site_option( 'tips_version' ) ) >= 0 ) { + $tips_table1 = 'ALTER TABLE `' . $wpdb->base_prefix . "tips` ADD `tip_status` INT( 1 ) NOT NULL DEFAULT '1' AFTER `tip_added` ;"; + $wpdb->query( $tips_table1 ); } } else { - $tips_table1 = "CREATE TABLE IF NOT EXISTS `" . $wpdb->base_prefix . "tips` ( + $tips_table1 = 'CREATE TABLE IF NOT EXISTS `' . $wpdb->base_prefix . "tips` ( `tip_ID` bigint(20) unsigned NOT NULL auto_increment, `tip_site_ID` int(20) NOT NULL default '0', `tip_content` TEXT CHARACTER SET utf8, @@ -140,34 +142,34 @@ function tips_global_install() { PRIMARY KEY (`tip_ID`) ) {$charset_collate};"; $wpdb->query( $tips_table1 ); - update_site_option( "tips_installed", "yes" ); - update_site_option( "tips_version", $tips_current_version ); + update_site_option( 'tips_installed', 'yes' ); + update_site_option( 'tips_version', $tips_current_version ); } } /** - * + * * @global type $tips_menu_slug * @version 2.0 */ function tips_plug_pages() { global $tips_menu_slug; - - if (is_super_admin()) { - add_submenu_page( $tips_menu_slug, __('Tips', TIPS_LANG_DOMAIN), __('Tips', TIPS_LANG_DOMAIN), 'manage_options', 'manage-tips', 'tips_manage_output' ); + + if ( is_super_admin() ) { + add_submenu_page( $tips_menu_slug, __( 'Tips', 'tips' ), __( 'Tips', 'tips' ), 'manage_options', 'manage-tips', 'tips_manage_output' ); } } /** - * + * * @global type $user_id - * + * * @version 2.0 */ function tips_profile_option_update() { global $user_id; if ( '' !== $_POST['show_tips'] ) { - update_user_meta($user_id, 'show_tips', $_POST['show_tips']); + update_user_meta( $user_id, 'show_tips', $_POST['show_tips'] ); } } @@ -177,26 +179,25 @@ function tips_profile_option_update() { function tips_output() { global $wpdb, $tmp_tips_prefix, $tmp_tips_suffix, $current_user; - + //hide if turned off - $show_tips = get_user_meta($current_user->ID,'show_tips', true); + $show_tips = get_user_meta( $current_user->ID, 'show_tips', true ); if ( 'no' === $show_tips ) { - return; + return; } - - $dismissed_tips = isset($_COOKIE['tips_dismissed'])?maybe_unserialize(stripslashes($_COOKIE['tips_dismissed'])):array(); - if (count($dismissed_tips) > 0) { - $dismissed_tips_sql = "AND tip_ID NOT IN(" . join(',', $dismissed_tips) . ")"; + $dismissed_tips = isset( $_COOKIE['tips_dismissed'] ) ? maybe_unserialize( stripslashes( $_COOKIE['tips_dismissed'] ) ) : array(); + if ( 0 < count( $dismissed_tips ) ) { + $dismissed_tips_sql = 'AND tip_ID NOT IN(' . join( ',', $dismissed_tips ) . ')'; } else { - $dismissed_tips_sql = ""; + $dismissed_tips_sql = ''; } - $tmp_tips_count = $wpdb->get_var("SELECT COUNT(*) FROM " . $wpdb->base_prefix . "tips WHERE tip_site_ID = '" . $wpdb->siteid . "' AND tip_status = 1 {$dismissed_tips_sql} "); - if ($tmp_tips_count > 0){ - $tmp_tip = $wpdb->get_row("SELECT tip_ID, tip_content FROM " . $wpdb->base_prefix . "tips WHERE tip_site_ID = '" . $wpdb->siteid . "' AND tip_status = 1 {$dismissed_tips_sql} ORDER BY RAND() LIMIT 1"); + $tmp_tips_count = $wpdb->get_var( 'SELECT COUNT(*) FROM ' . $wpdb->base_prefix . "tips WHERE tip_site_ID = '" . $wpdb->siteid . "' AND tip_status = 1 {$dismissed_tips_sql} " ); + if ( $tmp_tips_count > 0 ) { + $tmp_tip = $wpdb->get_row( 'SELECT tip_ID, tip_content FROM ' . $wpdb->base_prefix . "tips WHERE tip_site_ID = '" . $wpdb->siteid . "' AND tip_status = 1 {$dismissed_tips_sql} ORDER BY RAND() LIMIT 1" ); $tmp_tip_content = $tmp_tips_prefix . $tmp_tip->tip_content . $tmp_tips_suffix; ?> -

[ ]

[ ]

+

[ ]

[ ]