11<?php
22
3- class AffilinetWidgetsPlugin
4- {
3+ class AffilinetWidgetsPlugin {
54
6- public function __construct ()
7- {
8- add_action ('admin_init ' , array ($ this , 'admin_init ' ));
9- add_action ('admin_menu ' , array ($ this , 'admin_menu ' ));
10- add_action ('widgets_init ' , array ($ this , 'register_widget ' ));
5+ public function __construct () {
116
12- add_action ('admin_enqueue_scripts ' , array ($ this , 'admin_enqueue_scripts ' ));
137
14- add_action ('plugins_loaded ' , array ($ this , 'load_textdomain ' ));
8+ add_action ( 'admin_init ' , array ( $ this , 'admin_init ' ) );
9+ add_action ( 'admin_menu ' , array ( $ this , 'admin_menu ' ) );
10+ add_action ( 'widgets_init ' , array ( $ this , 'register_widget ' ) );
1511
16- add_shortcode ( ' affilinet_widget ' , array ($ this , 'affilinet_product_widgets_shortcode ' ) );
12+ add_action ( ' admin_enqueue_scripts ' , array ( $ this , 'admin_enqueue_scripts ' ) );
1713
18- add_action ( 'admin_notices ' , array ( $ this , 'admin_notice ' ));
14+ add_action ( 'plugins_loaded ' , array ( $ this , 'load_textdomain ' ) );
1915
16+ add_shortcode ( 'affilinet_widget ' , array ( $ this , 'affilinet_product_widgets_shortcode ' ) );
2017
21- }
18+ add_action ( 'admin_notices ' , array ( $ this , 'admin_notice ' ) );
19+
20+
21+ add_filter ( 'plugin_action_links_ ' .plugin_basename (AFFILINET_PRODUCT_WIDGETS_PLUGIN_FILE ), array ( $ this , 'plugin_add_settings_link ' ) );
22+
23+
24+
25+
26+ }
2227
2328
2429 /**
2530 * Register Settings for admin area
2631 */
27- public function admin_init ()
28- {
29- register_setting ('affilinet-product-widgets-settings-group ' , 'affilinet_product_widgets_publisher_id ' );
30- register_setting ('affilinet-product-widgets-settings-group ' , 'affilinet_product_widgets_publisher_webservice_password ' );
32+ public function admin_init () {
33+ register_setting ( 'affilinet-product-widgets-settings-group ' , 'affilinet_product_widgets_publisher_id ' );
34+ register_setting ( 'affilinet-product-widgets-settings-group ' , 'affilinet_product_widgets_publisher_webservice_password ' );
3135 // this value will change with every update and can be used to hook the password change
32- register_setting ('affilinet-product-widgets-settings-group ' , 'affilinet_product_widgets_last_credential_change ' , array ('sanitize_callback ' => array ($ this , 'validate_credentials ' )));
36+ register_setting ( 'affilinet-product-widgets-settings-group ' , 'affilinet_product_widgets_last_credential_change ' , array (
37+ 'sanitize_callback ' => array (
38+ $ this ,
39+ 'validate_credentials '
40+ )
41+ ) );
3342 }
3443
3544
36-
37- function validate_credentials ($ timestamp )
38- {
39- // clear the cache to get the new values
40- wp_cache_delete ( 'alloptions ' , 'options ' );
45+ function validate_credentials ( $ timestamp ) {
46+ // clear the cache to get the new values
47+ wp_cache_delete ( 'alloptions ' , 'options ' );
4148
4249 // check credentials
43- if (AffilinetWidgetsApi::logon () === false ) {
44- add_settings_error ('affilinet_product_widgets_publisher_webservice_password ' , '1 ' , __ ('Invalid Webservice Password or Publisher ID ' , 'affilinet-product-widgets ' ) );
45- update_option ('affilinet_product_widgets_webservice_login_is_correct ' , 'false ' , true );
46- wp_cache_delete ( 'alloptions ' , 'options ' );
47- return $ timestamp ;
48- }
49- return $ timestamp ;
50+ if ( AffilinetWidgetsApi::logon () === false ) {
51+ add_settings_error ( 'affilinet_product_widgets_publisher_webservice_password ' , '1 ' , __ ( 'Invalid Webservice Password or Publisher ID ' , 'affilinet-product-widgets ' ) );
52+ update_option ( 'affilinet_product_widgets_webservice_login_is_correct ' , 'false ' , true );
53+ wp_cache_delete ( 'alloptions ' , 'options ' );
54+
55+ return $ timestamp ;
56+ }
57+
58+ return $ timestamp ;
5059 }
5160
5261 function admin_notice () {
5362
54- if (get_option ('affilinet_product_widgets_webservice_login_is_correct ' , 'false ' ) === 'false ' ) {
55- ?>
63+ if ( get_option ( 'affilinet_product_widgets_webservice_login_is_correct ' , 'false ' ) === 'false ' ) {
64+ ?>
5665 <div class="notice notice-warning is-dismissible">
57- <p><?php _e ('<strong>affilinet Widgets:</strong><br> Please make sure you have entered the correct Publisher ID and Publisher Webservice password. ' , 'affilinet-product-widgets ' ); ?>
58- <a class="button" href="<?php echo admin_url ( 'options-general.php?page=affilinet-product-widgets-settings ' ) ;?> "><?php _e ('Check your settings. ' , 'affilinet-product-widgets ' );?> </a>
66+ <p><?php _e ( '<strong>affilinet Widgets:</strong><br> Please make sure you have entered the correct Publisher ID and Publisher Webservice password. ' , 'affilinet-product-widgets ' ); ?>
67+ <a class="button"
68+ href="<?php echo admin_url ( 'options-general.php?page=affilinet-product-widgets-settings ' ); ?> "><?php _e ( 'Check your settings. ' , 'affilinet-product-widgets ' ); ?> </a>
5969
6070 </p>
6171 </div>
62- <?php
63- }
64- }
65-
66-
67-
68- /**
69- * Create the admin Menu
70- */
71- public function admin_menu ()
72- {
73- // options menu
74- add_options_page ('affilinet Widgets Settings ' , 'affilinet Widgets ' , 'manage_options ' , 'affilinet-product-widgets-settings ' , 'AffilinetWidgetsView::settings ' );
75- }
76-
77- /**
78- * Register the widget
79- */
80- public function register_widget ()
81- {
82- register_widget ('AffilinetWidgetsWidget ' );
83- }
84-
85- /**
86- * Load Admin scripts
87- * @param $hook string
88- */
89- public function admin_enqueue_scripts ($ hook )
90- {
91- // on post page add the editor button for affilinet plugin
92- if ($ hook === 'post.php ' || $ hook == 'post-new.php ' ) {
93- add_action ('admin_head ' , array ($ this , 'register_tiny_mce_buttons ' ));
94- add_action ( "admin_head- $ hook " ,array ($ this , 'add_tiny_mce_variables ' ) );
95- }
96-
97- // on settings page integrate font awesome
98-
99- if ($ hook == 'settings_page_affilinet-product-widgets-settings ' ) {
100- wp_enqueue_style ('font-awesome ' , '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css ' );
101- }
102-
103- }
72+ <?php
73+ }
74+ }
75+
76+
77+ /**
78+ * Create the admin Menu
79+ */
80+ public function admin_menu () {
81+ // options menu
82+ add_options_page ( 'affilinet Widgets Settings ' , 'affilinet Widgets ' , 'manage_options ' , 'affilinet-product-widgets-settings ' , 'AffilinetWidgetsView::settings ' );
83+ }
84+
85+ /**
86+ * Register the widget
87+ */
88+ public function register_widget () {
89+ register_widget ( 'AffilinetWidgetsWidget ' );
90+ }
91+
92+
93+ /**
94+ * Load Admin scripts
95+ *
96+ * @param $hook string
97+ */
98+ public function admin_enqueue_scripts ( $ hook ) {
99+ // on post page add the editor button for affilinet plugin
100+ if ( $ hook === 'post.php ' || $ hook == 'post-new.php ' ) {
101+ add_action ( 'admin_head ' , array ( $ this , 'register_tiny_mce_buttons ' ) );
102+ add_action ( "admin_head- $ hook " , array ( $ this , 'add_tiny_mce_variables ' ) );
103+ }
104+
105+ // on settings page integrate font awesome
106+
107+ if ( $ hook == 'settings_page_affilinet-product-widgets-settings ' ) {
108+ wp_enqueue_style ( 'font-awesome ' , '//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css ' );
109+ }
110+
111+ }
112+
113+ public function plugin_add_settings_link ( $ links ) {
114+
115+ $ settings_link = '<a href=" ' . admin_url ( 'options-general.php?page=affilinet-product-widgets-settings ' ) . '"> ' . __ ( 'Settings ' ) . '</a> ' ;
116+ array_push ( $ links , $ settings_link );
117+ return $ links ;
118+ }
104119
105120
106121 /**
@@ -110,83 +125,77 @@ public function admin_enqueue_scripts($hook)
110125 *
111126 * @return string
112127 */
113- public function affilinet_product_widgets_shortcode ($ params = array ())
114- {
115- // default $widget_id parameter
116- /**
117- * @var String $size
118- */
119- extract (shortcode_atts (array (
120- 'id ' => 'notset ' ,
121- ), $ params ));
122-
123- return AffilinetWidgetsWidget::getAdCode ($ params ['id ' ]);
124- }
125-
126- /**
127- * TRANSLATION
128- */
129- public function load_textdomain ()
130- {
131- load_plugin_textdomain ( 'affilinet-product-widgets ' , false , dirname (dirname ( plugin_basename ( __FILE__ ) )) . '/languages ' );
132- }
133-
134- /**
135- * TinyMCE Editor Button
136- */
137- public function register_tiny_mce_buttons ()
138- {
139- // check user permissions
140- if (!current_user_can ('edit_posts ' ) && !current_user_can ('edit_pages ' )) {
141- return ;
142- }
143- // check if WYSIWYG is enabled
144- if (get_user_option ('rich_editing ' ) == 'true ' ) {
145- add_filter ('mce_external_plugins ' , array ($ this , 'add_buttons ' ));
146- add_filter ('mce_buttons ' , array ($ this , 'register_buttons ' ));
147- }
148- }
149-
150- /**
151- * Load TinyMCE Variables
152- */
153- public function add_tiny_mce_variables ()
154- {
155- $ img = plugin_dir_url ( plugin_basename ( dirname (__FILE__ )) ). 'images/ ' ;
156- $ widgets = AffilinetWidgetsApi::getMyWidgets ();
157- $ widgetsForTinyMce = [];
158- foreach ($ widgets as $ widget ) {
159- $ widgetsForTinyMce [] = [
160- 'value ' => $ widget ['id ' ],
161- 'id ' => $ widget ['id ' ],
162- 'text ' => $ widget ['widgetName ' ],
163- ];
164- }
165- ?>
128+ public function affilinet_product_widgets_shortcode ( $ params = array () ) {
129+ // default $widget_id parameter
130+ /**
131+ * @var String $size
132+ */
133+ extract ( shortcode_atts ( array (
134+ 'id ' => 'notset ' ,
135+ ), $ params ) );
136+
137+ return AffilinetWidgetsWidget::getAdCode ( $ params ['id ' ] );
138+ }
139+
140+ /**
141+ * TRANSLATION
142+ */
143+ public function load_textdomain () {
144+ load_plugin_textdomain ( 'affilinet-product-widgets ' , false , dirname ( dirname ( plugin_basename ( __FILE__ ) ) ) . '/languages ' );
145+ }
146+
147+ /**
148+ * TinyMCE Editor Button
149+ */
150+ public function register_tiny_mce_buttons () {
151+ // check user permissions
152+ if ( ! current_user_can ( 'edit_posts ' ) && ! current_user_can ( 'edit_pages ' ) ) {
153+ return ;
154+ }
155+ // check if WYSIWYG is enabled
156+ if ( get_user_option ( 'rich_editing ' ) == 'true ' ) {
157+ add_filter ( 'mce_external_plugins ' , array ( $ this , 'add_buttons ' ) );
158+ add_filter ( 'mce_buttons ' , array ( $ this , 'register_buttons ' ) );
159+ }
160+ }
161+
162+ /**
163+ * Load TinyMCE Variables
164+ */
165+ public function add_tiny_mce_variables () {
166+ $ img = plugin_dir_url ( plugin_basename ( dirname ( __FILE__ ) ) ) . 'images/ ' ;
167+ $ widgets = AffilinetWidgetsApi::getMyWidgets ();
168+ $ widgetsForTinyMce = [];
169+ foreach ( $ widgets as $ widget ) {
170+ $ widgetsForTinyMce [] = [
171+ 'value ' => $ widget ['id ' ],
172+ 'id ' => $ widget ['id ' ],
173+ 'text ' => $ widget ['widgetName ' ],
174+ ];
175+ }
176+ ?>
166177 <!-- TinyMCE Shortcode Plugin -->
167178 <script type='text/javascript'>
168179 var affilinet_product_widgets_mce_variables = {
169180 'image_path': '<?php echo $ img ; ?> ',
170181 'choose_widget': 'Choose widget',
171- 'widgets' : <?php echo json_encode ($ widgetsForTinyMce , JSON_PRETTY_PRINT ); ?> ,
182+ 'widgets': <?php echo json_encode ( $ widgetsForTinyMce , JSON_PRETTY_PRINT ); ?> ,
172183 };
173184 </script>
174185 <!-- TinyMCE Shortcode Plugin -->
175- <?php
176- }
186+ <?php
187+ }
177188
178- public function add_buttons ($ plugin_array )
179- {
180- $ plugin_array ['affilinet_product_widgets_mce_button ' ] = plugin_dir_url ( plugin_basename ( dirname (__FILE__ ) ) ). 'js/affilinet_product_widgets_mce_button.js ' ;
189+ public function add_buttons ( $ plugin_array ) {
190+ $ plugin_array ['affilinet_product_widgets_mce_button ' ] = plugin_dir_url ( plugin_basename ( dirname ( __FILE__ ) ) ) . 'js/affilinet_product_widgets_mce_button.js ' ;
181191
182- return $ plugin_array ;
183- }
192+ return $ plugin_array ;
193+ }
184194
185- public function register_buttons ($ buttons )
186- {
187- array_push ($ buttons , 'affilinet_product_widgets_mce_button ' );
195+ public function register_buttons ( $ buttons ) {
196+ array_push ( $ buttons , 'affilinet_product_widgets_mce_button ' );
188197
189- return $ buttons ;
190- }
198+ return $ buttons ;
199+ }
191200
192201}
0 commit comments