PluginProbe
WPAdverts – Classifieds Plugin / 2.3.2
WPAdverts – Classifieds Plugin v2.3.2
2.3.4 2.3.3 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.2.0 All 88 releases
wpadverts / wpadverts.php

wpadverts.php in WPAdverts – Classifieds Plugin 2.3.2, at wpadverts.php

797 lines 30.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 * Plugin Name: WP Adverts
4 * Plugin URI: https://wpadverts.com/
5 * Description: The lightweight WordPress classifieds plugin done right.
6 * Author: Greg Winiarski
7 * Text Domain: wpadverts
8 * Domain Path: /languages
9 * Version: 2.3.2
10 *
11 * Adverts is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation, either version 2 of the License, or
14 * any later version.
15 *
16 * Adverts is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with Adverts. If not, see <http://www.gnu.org/licenses/>.
23 *
24 * @package Adverts
25 * @category Core
26 * @author Grzegorz Winiarski
27 * @version 1.0.0
28 */
29
30 if( !defined("ADVERTS_FILE") ) {
31 define( "ADVERTS_FILE", __FILE__ );
32 define( "ADVERTS_PATH", plugin_dir_path( ADVERTS_FILE ) );
33 define( "ADVERTS_URL", plugins_url() . "/" . basename(ADVERTS_PATH) );
34 }
35
36 // init global variables
37 global $wpadverts, $adverts_config, $adverts_namespace;
38
39 // define global $wpadverts variable
40 $wpadverts = null;
41
42 // define global $adverts_config variable
43 $adverts_config = null;
44
45 // define global $adverts_namespace variable
46 $adverts_namespace = array();
47
48 $adverts_namespace['config'] = array(
49 'option_name' => 'adverts_config',
50 'default' => array(
51 'module' => array(),
52 'license' => array(),
53 'currency_code' => 'USD',
54 'currency_sign' => '$',
55 'currency_sign_type' => 'p', // either p=prefix or s=suffix
56 'currency_decimals' => 2,
57 'currency_char_decimal' => '.',
58 'currency_char_thousand' => ',',
59 'visibility' => 30,
60 'ads_list_id' => null,
61 'ads_list_default__search_bar' => 'enabled',
62 'ads_list_default__columns' => 2,
63 'ads_list_default__display' => 'grid',
64 'ads_list_default__switch_views' => 0,
65 'ads_list_default__posts_per_page' => 20,
66 'expired_ad_status' => '404', // one of: 404, 200, 301
67 'expired_ad_redirect_url' => '',
68 'expired_ad_public_cap' => 'edit_pages',
69 'empty_price' => '',
70 'hide_images_in_media_library' => 0,
71 'delete_from_media_library' => 0,
72 'adverts_manage_moderate' => 0,
73 'block_date_format' => 'd/m/Y',
74
75 )
76 );
77
78 $adverts_namespace['gallery'] = array(
79 'option_name' => 'adverts_gallery',
80 'default' => array(
81 'ui' => 'pagination', // either paginator or thumbnails
82 'visible_items' => 5,
83 'scrolling_items' => 1,
84 'lightbox' => 1,
85 'image_fit' => 'contain',
86 'image_edit_cap' => 'read',
87 'image_sizes' => array(
88 // supported sizes: adverts-upload-thumbnail, adverts-list, adverts-gallery
89 "adverts-gallery" => array( 'enabled' => 1, 'width' => 650, 'height' => 300, 'crop' => false ),
90 "adverts-list" => array( 'enabled' => 1, 'width' => 310, 'height' => 310, 'crop' => false ),
91 "adverts-upload-thumbnail" => array( 'enabled' => 1, 'width' => 150, 'height' => 105, 'crop' => false ),
92 //"adverts-gallery-thumbnail"
93 ),
94 'image_editor' => ''
95 )
96 );
97
98 $adverts_namespace['moderate'] = array(
99 "option_name" => "adverts_moderate",
100 "default" => array(
101 "max_links" => "",
102 "phrases_moderate" => "",
103 "phrases_trash" => "",
104 "phrases_match_type" => "partial",
105
106 "honeypot_enabled" => "1",
107 "honeypot_title" => "Website Address",
108 "honeypot_name" => "website_address",
109
110 "timetrap_enabled" => "1",
111 "timetrap_delta" => "5",
112 "timetrap_salt" => ""
113 )
114 );
115
116 $adverts_namespace['blocks_styling'] = array(
117 "option_name" => "adverts_blocks_styling",
118 "default" => array(
119 "primary_button" => array(
120 "border_radius" => "2",
121 "border_width" => "1",
122 "font_weight" => "atw-font-bold",
123 "color_text" => "#ffffff",
124 "color_bg" => "#e25a58",
125 "color_border" => "#e25a58",
126 "color_text_h" => "#ffffff",
127 "color_bg_h" => "#c44c4c",
128 "color_border_h" => "#c44c4c"
129 ),
130 "secondary_button" => array(
131 "border_radius" => "2",
132 "border_width" => "1",
133 "font_weight" => "atw-font-normal",
134 "color_text" => "#6b7280",
135 "color_bg" => "#e5e7eb",
136 "color_border" => "#e5e7eb",
137 "color_text_h" => "#374151",
138 "color_bg_h" => "#e5e7eb",
139 "color_border_h" => "#e5e7eb"
140 ),
141 "form" => array(
142 "style" => "wpa-solid",
143 "shadow" => "wpa-shadow-none",
144 "palette" => "cool-gray",
145 "rounded" => 3,
146 "px" => 0,
147 "py" => 0,
148 "border" => 1,
149 "interline" => 1,
150 "spacing" => 0
151 )
152 )
153 );
154
155 /**
156 * Main Adverts Init Function
157 *
158 * Registers: custom post types, additional post statuses, taxonomies, image sizes
159 * and Adverts scripts.
160 *
161 * @global WP_Embed $wp_embed
162 * @global WP_Rewrite $wp_rewrite
163 * @since 0.1
164 * @return void
165 */
166 function adverts_init() {
167 global $wp_embed, $wpadverts;
168
169 add_filter( 'adverts_the_content', array( $wp_embed, 'autoembed' ), 8 );
170 add_filter( 'adverts_the_content', 'wptexturize' );
171 add_filter( 'adverts_the_content', 'convert_chars' );
172 add_filter( 'adverts_the_content', 'wpautop' );
173
174 add_action( 'save_post_advert', 'adverts_create_hash', 10, 3 );
175 add_action( 'deleted_post', 'adverts_deleted_post', 10, 2 );
176
177 add_filter( 'adverts_form_load', 'adverts_form_load_checksum_fields', 9999 );
178
179 wp_register_style( 'wpadverts-autocomplete', ADVERTS_URL . '/assets/css/wpadverts-autocomplete.css', array(), "1.4.5" );
180 wp_register_style( 'adverts-upload', ADVERTS_URL . '/assets/css/wpadverts-upload.css', array(), "1.5.4" );
181 wp_register_style( 'adverts-icons', ADVERTS_URL . '/assets/css/wpadverts-glyphs.css', array(), "4.7.2" );
182 wp_register_style( 'adverts-icons-animate', ADVERTS_URL . '/assets/css/animation.css', array(), "1.3.5" );
183
184 wp_register_style( 'wpadverts-blocks-common', ADVERTS_URL . '/assets/css/all.min.css', array(), "2.0.0" );
185 wp_register_style( 'wpadverts-blocks', ADVERTS_URL . '/assets/css/blocks.min.css', array( 'wpadverts-blocks-common' ), filemtime( ADVERTS_PATH . '/assets/css/blocks.min.css' ) );
186
187 wp_register_script('adverts-form', ADVERTS_URL . '/assets/js/wpadverts-form.js', array( 'jquery' ), "1.5.2" );
188
189 load_plugin_textdomain("wpadverts", false, dirname(plugin_basename(__FILE__))."/languages/");
190
191 include_once ADVERTS_PATH . 'includes/class-adverts.php';
192 $wpadverts = Adverts::instance();
193
194 include_once ADVERTS_PATH . 'includes/functions.php';
195
196 $expired_status = adverts_config( 'expired_ad_status' );
197 $public_cap = adverts_config( 'expired_ad_public_cap' );
198 if( is_admin() ) {
199 // current user is viewing admin panel
200 $expired_is_public = is_admin();
201 } else if( $public_cap && current_user_can( $public_cap ) ) {
202 // current user can always see expired Ads.
203 $expired_is_public = true;
204 add_action( "wp", "adverts_handle_expired_ads" );
205 } else if( $expired_status == '404' ) {
206 // show 404 page
207 $expired_is_public = false;
208 } else if( $expired_status == '301' ) {
209 // redirect (301) to some other page.
210 $expired_is_public = true;
211 add_action( "template_redirect", "adverts_template_redirect_expired" );
212 } else {
213 // most likely 200
214 $expired_is_public = true;
215 add_action( "wp", "adverts_handle_expired_ads" );
216 }
217
218 if( adverts_config( 'hide_images_in_media_library' ) == 1 ) {
219 add_action( "ajax_query_attachments_args", "adverts_query_attachments_args" );
220 }
221
222 register_post_status( 'expired', array(
223 'label' => _x( 'Expired', 'post' ),
224 'public' => $expired_is_public,
225 'internal' => false,
226 'label_count' => _n_noop( 'Expired <span class="count">(%s)</span>', 'Expired <span class="count">(%s)</span>' )
227 ) );
228
229 register_post_status( 'advert_tmp', array(
230 'label' => _x( 'Temporary', 'post' ),
231 'public' => false,
232 'internal' => false,
233 'show_in_admin_all_list' => false,
234 'label_count' => _n_noop( 'Temporary <span class="count">(%s)</span>', 'Temporary <span class="count">(%s)</span>' )
235 ) );
236
237 $labels = array(
238 'name' => _x( 'Classifieds', 'post type general name', 'wpadverts' ),
239 'singular_name' => _x( 'Classified', 'post type singular name', 'wpadverts' ),
240 'add_new' => _x( 'Add New', 'classified', 'wpadverts' ),
241 'add_new_item' => __( 'Add New Classified', 'wpadverts' ),
242 'edit_item' => __( 'Edit Classified', 'wpadverts' ),
243 'new_item' => __( 'New Classified', 'wpadverts' ),
244 'all_items' => __( 'All Classifieds', 'wpadverts' ),
245 'view_item' => __( 'View Classified', 'wpadverts' ),
246 'search_items' => __( 'Search Classifieds', 'wpadverts' ),
247 'not_found' => __( 'No Classifieds found', 'wpadverts' ),
248 'not_found_in_trash' => __( 'No Classifieds found in the Trash', 'wpadverts' ),
249 'parent_item_colon' => '',
250 'menu_name' => __( 'Classifieds', 'wpadverts' )
251 );
252
253 $args = array(
254 'labels' => $labels,
255 'description' => '',
256 'public' => true,
257 'menu_icon' => 'dashicons-megaphone',
258 'menu_position' => 5,
259 'supports' => array( 'title', 'editor', 'author' ),
260 'taxonomies' => array( 'advert_category' ),
261 'has_archive' => true,
262 'rewrite' => array(
263 'slug' => 'advert',
264 'with_front' => false,
265 'feeds' => true
266 ),
267 'show_in_rest' => adverts_show_in_rest( true, "advert" )
268 );
269
270 include_once ADVERTS_PATH . "/includes/class-types.php";
271 $adverts_types = new Adverts_Types();
272
273 register_post_type( 'advert', apply_filters( 'adverts_post_type', $args, 'advert') );
274
275 $labels = array(
276 'name' => _x( 'Adverts Categories', 'taxonomy general name', 'wpadverts' ),
277 'singular_name' => _x( 'Advert Category', 'taxonomy singular name', 'wpadverts' ),
278 'menu_name' => __( 'Categories', 'wpadverts' ),
279 );
280
281 $args = array(
282 'labels' => $labels,
283 'hierarchical' => true,
284 'query_var' => true,
285 'show_in_rest' => true,
286 'rewrite' => array('slug' => 'advert-category')
287 );
288
289 register_taxonomy(
290 'advert_category',
291 apply_filters('adverts_register_taxonomy_post_type', 'advert', 'advert_category' ),
292 apply_filters('adverts_register_taxonomy', $args, 'advert_category')
293 );
294
295 include_once ADVERTS_PATH . 'includes/class-adverts.php';
296 include_once ADVERTS_PATH . 'includes/class-taxonomies.php';
297 include_once ADVERTS_PATH . 'includes/class-flash.php';
298 include_once ADVERTS_PATH . 'includes/class-post.php';
299 include_once ADVERTS_PATH . 'includes/events.php';
300 include_once ADVERTS_PATH . 'includes/functions.php';
301
302 include_once ADVERTS_PATH . 'includes/defaults.php';
303
304 foreach( adverts_config( "gallery.image_sizes" ) as $image_key => $image_size ) {
305 if( $image_size["enabled"] ) {
306 add_image_size( $image_key, $image_size["width"], $image_size["height"], $image_size["crop"] );
307 }
308 }
309
310 $currency = Adverts::instance()->get("currency");
311
312 Adverts::instance()->set( "taxonomies", new Adverts_Taxonomies() );
313
314 wp_register_script(
315 'adverts-auto-numeric',
316 ADVERTS_URL .'/assets/js/auto-numeric.js',
317 array( 'jquery' ),
318 "4.10.4",
319 true
320 );
321
322 wp_register_script(
323 'adverts-autocomplete',
324 ADVERTS_URL . '/assets/js/wpadverts-autocomplete.js',
325 array( 'jquery' ),
326 "1.4.4",
327 true
328 );
329
330 wp_register_script(
331 'adverts-multiselect',
332 ADVERTS_URL . '/assets/js/wpadverts-multiselect.js',
333 array( 'jquery' ),
334 "2.1.4",
335 true
336 );
337
338 wp_register_script(
339 'adverts-gallery',
340 ADVERTS_URL . '/assets/js/wpadverts-gallery.js',
341 array( 'jquery', 'plupload-all', 'jquery-ui-sortable', 'jquery-effects-core', 'jquery-effects-fade', 'wp-util', 'jcrop' ),
342 "1.5.6",
343 true
344 );
345
346 wp_register_script(
347 'adverts-slick',
348 ADVERTS_URL . '/assets/js/slick.min.js',
349 array( 'jquery' ),
350 "1.8.1",
351 true
352 );
353
354 wp_register_script(
355 'wpadverts-tiny-slider',
356 ADVERTS_URL . '/assets/js/tiny-slider.js',
357 array(),
358 "2.9.2",
359 true
360 );
361
362 wp_register_script(
363 'wpadverts-glightbox',
364 ADVERTS_URL . '/assets/js/glightbox.min.js',
365 array(),
366 "3.3.0",
367 true
368 );
369
370 wp_register_style(
371 'wpadverts-glightbox',
372 ADVERTS_URL . '/assets/css/glightbox.min.css',
373 array(),
374 "3.3.0"
375 );
376
377
378 wp_localize_script( 'adverts-auto-numeric', 'adverts_currency', array(
379 "aSign" => $currency["sign"],
380 "pSign" => $currency["sign_type"],
381 "aSep" => $currency["char_thousand"],
382 "aDec" => $currency["char_decimal"],
383 "mDec" => $currency["decimals"]
384 ));
385
386 wp_localize_script( 'adverts-multiselect', 'adverts_multiselect_lang', array(
387 "hint" => __("Select options ...", "wpadverts")
388 ));
389
390 wp_localize_script( 'adverts-autocomplete', 'adverts_autocomplete_lang', array(
391 "ajaxurl" => adverts_ajax_url(),
392 "no_results" => __( "No results found.", "wpadverts" ),
393 "open" => __( "Open", "wpadverts" ),
394 "close" => __( "Close", "wpadverts" ),
395 "ok" => __( "OK", "wpadverts" ),
396 "cancel" => __( "Cancel", "wpadverts" ),
397 "selected" => __( "Selected", "wpadverts" ),
398 "max_choices" => __( "Cannot select more than %s items.", "wpadverts" ),
399 "search_placeholder" => __( "Type in the box above to see suggestions ...", "wpadverts" ),
400 "start_typing_here" => __( "start typing here ...", "wpadverts" )
401 ));
402
403 wp_localize_script( 'adverts-gallery', 'adverts_gallery_lang', array(
404 "ajaxurl" => adverts_ajax_url(),
405 "edit_image" => __( "Edit Image", "wpadverts" ),
406 "delete_image" => __( "Delete Image", "wpadverts" ),
407 "view_image" => __( "View Full Image", "wpadverts" ),
408 "featured" => __( "Main", "wpadverts" ),
409 ));
410
411 $module = adverts_config( 'config.module' );
412
413 foreach((array)$module as $mod => $status) {
414 if(!is_file(ADVERTS_PATH . "addons/$mod/$mod.php")) {
415 continue;
416 }
417 if($status > 0) {
418 include_once ADVERTS_PATH . "addons/$mod/$mod.php";
419 }
420 if($status == 0.5) {
421 add_action("init", "adverts_install_modules", 1000);
422 }
423 }
424
425 if( get_option( "adverts_delayed_install" ) == "yes" ) {
426 global $wp_rewrite;
427 $wp_rewrite->flush_rules();
428
429 delete_option( "adverts_delayed_install" );
430 }
431
432 include_once ADVERTS_PATH . "/blocks/class-block-manager.php";
433 $block_manager = new Adverts_Block_Manager( ADVERTS_PATH . "blocks/" );
434 $block_manager->register();
435
436 Adverts::instance()->set( "block_manager", $block_manager );
437
438 include_once ADVERTS_PATH . "/blocks/class-block-patterns.php";
439 $block_patterns = new Adverts_Block_Patterns( );
440 $block_patterns->register_categories();
441 $block_patterns->register_patterns();
442
443 Adverts::instance()->set( "block_patterns", $block_patterns );
444
445 do_action("adverts_core_initiated");
446 }
447
448 /**
449 * Frontend Adverts Init Function
450 *
451 * Registers frontend: scripts, styles and shortcodes
452 *
453 * @since 0.1
454 * @return void
455 */
456 function adverts_init_frontend() {
457 ;
458 wp_register_style( 'adverts-frontend', ADVERTS_URL . '/assets/css/wpadverts-frontend.css', array(), "1.5.3" );
459 wp_register_style( 'adverts-swipebox', ADVERTS_URL . '/assets/css/swipebox.min.css', array(), "1.4.5" );
460 wp_register_style( 'wpadverts-tiny-slider', ADVERTS_URL . '/assets/css/tiny-slider.css', array(), "2.9.4");
461
462 wp_register_script('adverts-single', ADVERTS_URL . '/assets/js/wpadverts-single.js', array( 'jquery' ), "1.4.0" );
463 wp_register_script('adverts-frontend', ADVERTS_URL . '/assets/js/wpadverts-frontend.js', array( 'jquery' ), "2.1.7" );
464 wp_register_script('adverts-frontend-add', ADVERTS_URL . '/assets/js/wpadverts-frontend-add.js', array( 'jquery'), "1.4.0" );
465 wp_register_script('adverts-frontend-manage', ADVERTS_URL . '/assets/js/wpadverts-frontend-manage.js', array( 'jquery'), "1.3.5" );
466 wp_register_script('adverts-swipebox', ADVERTS_URL . '/assets/js/jquery.swipebox.js', array( 'jquery', 'adverts-frontend' ), "1.4.5");
467
468 include_once ADVERTS_PATH . 'includes/functions.php';
469 include_once ADVERTS_PATH . 'includes/gallery.php';
470 include_once ADVERTS_PATH . 'includes/shortcodes.php';
471
472 add_filter('the_content', 'adverts_the_content', 9999 );
473
474 // Below filters and actions were removed in version 1.4.0 in favor of Adverts_Taxonomies class
475 // add_filter('posts_results', 'adverts_posts_results', 10, 2 );
476 // add_filter('template_include', 'adverts_template_include');
477
478 //add_action('template_redirect', 'adverts_disable_default_archive');
479
480 add_filter('post_thumbnail_html', 'adverts_post_thumbnail_html');
481 add_action('adverts_new_user_notification', 'wp_new_user_notification', 10, 3 );
482 add_filter('post_class', 'adverts_post_class' );
483
484 add_action('adverts_tpl_single_top', 'adverts_single_rslides');
485 add_action('adverts_tpl_single_bottom', 'adverts_single_contact_information');
486
487 add_filter('adverts_create_user_from_post_id', '_adverts_create_user_from_post_id', 20, 2 );
488 add_action('template_redirect', 'adverts_skip_preview' );
489
490 wp_localize_script( 'adverts-frontend', 'adverts_frontend_lang', array(
491 "ajaxurl" => adverts_ajax_url(),
492 "als_visible_items" => adverts_config( "gallery.visible_items" ),
493 "als_scrolling_items" => adverts_config( "gallery.scrolling_items" ),
494 "lightbox" => adverts_config( "gallery.lightbox" )
495 ) );
496
497 wp_localize_script( 'adverts-frontend-manage', 'adverts_frontend_manage_lang', array(
498 "ajaxurl" => adverts_ajax_url(),
499 "ok" => __( "OK", "wpadverts" )
500 ) );
501
502 if(wp_get_theme()->get_template() == "twentytwelve") {
503 add_action("wp_head", "adverts_css_rem_fix");
504 }
505
506 if( adverts_config( "moderate.honeypot_enabled" ) == "1" ) {
507 include_once ADVERTS_PATH . 'includes/class-honeypot.php';
508 $wpadverts_honeypot = new WPAdverts_Honeypot();
509 $wpadverts_honeypot->register_field_and_validator();
510 }
511
512 if(adverts_config( "moderate.timetrap_enabled" ) == "1" ) {
513 include_once ADVERTS_PATH . 'includes/class-timetrap.php';
514 $wpadverts_timetrap = new WPAdverts_Timetrap();
515 $wpadverts_timetrap->register_field_and_validator();
516 }
517
518 add_filter( 'adverts_form_load', 'adverts_discard_spam_content', 10, 2 );
519 add_filter( 'adverts_form_load', 'adverts_post_title_kses' );
520 }
521
522 /**
523 * Adverts Admin Init Function
524 *
525 * Registers admin: ajax actions, scripts, styles and meta boxes when adding new advert.
526 *
527 * @since 0.1
528 * @return void
529 */
530 function adverts_init_admin() {
531
532 include_once ADVERTS_PATH . 'includes/ajax.php';
533 include_once ADVERTS_PATH . 'includes/admin-pages.php';
534 include_once ADVERTS_PATH . 'includes/admin-post-type.php';
535 include_once ADVERTS_PATH . 'includes/class-form.php';
536 include_once ADVERTS_PATH . 'includes/class-html.php';
537 include_once ADVERTS_PATH . 'includes/gallery.php';
538
539 add_action( 'add_meta_boxes', 'adverts_data_box' );
540 add_action( 'add_meta_boxes', 'adverts_box_gallery' );
541
542 wp_register_script('adverts-admin', ADVERTS_URL . '/assets/js/wpadverts-admin.js', array( 'jquery' ), "1.3.5", true);
543 wp_register_script('adverts-admin-config-core', ADVERTS_URL . '/assets/js/wpadverts-admin-config-core.js', array( 'jquery' ), "1.3.5", true);
544 wp_register_style('adverts-admin', ADVERTS_URL . '/assets/css/wpadverts-admin.css', array(), "1.4.4" );
545
546 wp_register_script( 'adverts-admin-updates', ADVERTS_URL . '/assets/js/wpadverts-admin-updates.js', array( 'jquery' ), "1.3.5", true );
547 wp_register_style( 'adverts-admin-updates', ADVERTS_URL . '/assets/css/wpadverts-admin-updates.css', array(), "1.5.3" );
548
549 wp_register_script( 'adverts-types-post', ADVERTS_URL . '/assets/js/wpadverts-types-post.js', array( 'jquery' ), "1.6.0", true );
550 wp_register_script( 'adverts-admin-styling', ADVERTS_URL . '/assets/js/wpadverts-admin-styling.js', array( 'jquery' ), "2.0.0", true );
551
552 wp_localize_script( 'adverts-admin-styling', 'adverts_admin_styling_lang', array(
553 "ajax" => admin_url( 'admin-ajax.php' ),
554 "are_you_sure" => __( "Are you sure you want to reset this settings to defaults?", "wpadverts" )
555 ));
556
557 add_filter( 'display_post_states', 'adverts_display_expired_state' );
558 add_action( 'post_submitbox_misc_actions', 'adverts_expiry_meta_box' );
559
560 add_action( 'admin_print_scripts-post-new.php', 'adverts_admin_script', 11 );
561 add_action( 'admin_print_scripts-post.php', 'adverts_admin_script', 11 );
562 add_action( 'admin_print_scripts-edit.php', 'adverts_admin_script', 11 );
563
564 add_action( 'admin_head', 'adverts_admin_head' );
565 add_filter( 'wp_insert_post_data', 'adverts_insert_post_data');
566 add_action( 'save_post', 'adverts_save_post', 10, 2 );
567 add_action( 'save_post', 'adverts_save_post_validator', 10, 2 );
568
569 add_filter( 'post_updated_messages', 'adverts_post_updated_messages');
570
571 add_filter( 'add_menu_classes', 'adverts_add_menu_classes' );
572 add_action( 'wpadverts_admin_types_after_title', 'wpadverts_multiverse_promo' );
573
574 // Adverts category meta handlers
575 add_action( 'edited_advert_category', 'adverts_save_category', 10, 2);
576 add_action( 'advert_category_edit_form_fields', 'adverts_category_form_fields', 10, 2);
577
578 // Preserve Ad author when editing Ad via Quick Edit
579 add_filter( "wp_insert_post_data", "wpadverts_qe_preserve_author", 10, 2 );
580 add_action( "admin_footer", "wpadverts_qe_hide_author_field" );
581
582 // AJAX filters
583 add_action('wp_ajax_wpadverts-styling-save', 'wpadverts_admin_styling_save');
584 add_action('wp_ajax_wpadverts-styling-reset', 'wpadverts_admin_styling_reset');
585 add_action('wp_ajax_adverts_author_suggest', 'adverts_author_suggest');
586 add_action('wp_ajax_adverts_gallery_upload', 'adverts_gallery_upload');
587 add_action('wp_ajax_adverts_gallery_update', 'adverts_gallery_update');
588 add_action('wp_ajax_adverts_gallery_update_order', 'adverts_gallery_update_order');
589 add_action('wp_ajax_adverts_gallery_delete', 'adverts_gallery_delete');
590 add_action('wp_ajax_adverts_gallery_delete_file', 'adverts_gallery_delete_file');
591 add_action('wp_ajax_adverts_gallery_image_stream', 'adverts_gallery_image_stream');
592 add_action('wp_ajax_adverts_gallery_image_restore', 'adverts_gallery_image_restore');
593 add_action('wp_ajax_adverts_gallery_image_save', 'adverts_gallery_image_save');
594 add_action('wp_ajax_adverts_gallery_video_cover', 'adverts_gallery_video_cover');
595 add_action('wp_ajax_adverts_show_contact', 'adverts_show_contact');
596 add_action('wp_ajax_adverts_delete_tmp', 'adverts_delete_tmp');
597 add_action('wp_ajax_adverts_delete_tmp_files', 'adverts_delete_tmp_files');
598 add_action('wp_ajax_adverts_delete', 'adverts_delete');
599
600 add_action('wp_ajax_nopriv_adverts_gallery_upload', 'adverts_gallery_upload');
601 add_action('wp_ajax_nopriv_adverts_gallery_update', 'adverts_gallery_update');
602 add_action('wp_ajax_nopriv_adverts_gallery_update_order', 'adverts_gallery_update_order');
603 add_action('wp_ajax_nopriv_adverts_gallery_delete', 'adverts_gallery_delete');
604 add_action('wp_ajax_nopriv_adverts_gallery_delete_file', 'adverts_gallery_delete_file');
605 add_action('wp_ajax_nopriv_adverts_gallery_image_stream', 'adverts_gallery_image_stream');
606 add_action('wp_ajax_nopriv_adverts_gallery_image_restore', 'adverts_gallery_image_restore');
607 add_action('wp_ajax_nopriv_adverts_gallery_image_save', 'adverts_gallery_image_save');
608 add_action('wp_ajax_nopriv_adverts_gallery_video_cover', 'adverts_gallery_video_cover');
609
610 add_action('wp_ajax_nopriv_adverts_show_contact', 'adverts_show_contact');
611 add_action('wp_ajax_nopriv_adverts_delete_tmp', 'adverts_delete_tmp');
612 add_action('wp_ajax_nopriv_adverts_delete_tmp_files', 'adverts_delete_tmp_files');
613
614 add_filter( 'manage_edit-advert_columns', 'adverts_edit_columns' );
615 add_action( 'manage_advert_posts_custom_column', 'adverts_manage_post_columns', 10, 2 );
616 add_filter( 'manage_edit-advert_sortable_columns', 'adverts_admin_sortable_columns' );
617
618 /* Only run our customization on the 'edit.php' page in the admin. */
619 add_action( 'load-edit.php', 'adverts_admin_load' );
620
621 if(adverts_config( "delete_from_media_library") == 1) {
622 add_action( "before_delete_post", "adverts_before_delete_post", 10, 2 );
623 }
624 }
625
626 function adverts_rest_api_init() {
627 include_once ADVERTS_PATH . '/includes/class-rest-blocks.php';
628
629 $adverts_rest_blocks = new Adverts_Rest_Blocks();
630 }
631
632 /**
633 * Registers Adverts Widgets
634 *
635 * This function is executed by 'widgets_init' action.
636 *
637 * @since 0.3
638 * @return void
639 */
640 function adverts_widgets_init() {
641
642 include_once ADVERTS_PATH . '/includes/class-widget-categories.php';
643 include_once ADVERTS_PATH . '/includes/class-widget-ads.php';
644
645 register_widget( "Adverts_Widget_Categories" );
646 register_widget( "Adverts_Widget_Ads" );
647 }
648
649 /**
650 * Install Modules
651 *
652 * Run module installation functions (if any) on modules that were "just" activated.
653 * This function is executed in "init" filter with low priority so all the modules
654 * are initiated before it is run.
655 *
656 * @since 0.2
657 * @return void
658 */
659 function adverts_install_modules() {
660 $module = adverts_config( 'config.module' );
661 $install = array();
662
663 foreach((array)$module as $mod => $status) {
664 if(!is_file(ADVERTS_PATH . "addons/$mod/$mod.php")) {
665 continue;
666 }
667 if($status > 0) {
668 include_once ADVERTS_PATH . "addons/$mod/$mod.php";
669 }
670 if($status == 0.5) {
671 add_action("init", "adverts_install_modules");
672 Adverts_Flash::instance()->add_info( __( "Module activated successfully.", "wpadverts" ) );
673
674 $module[$mod] = 1;
675 adverts_config_set( 'config.module', $module );
676 adverts_config_save( 'config' );
677
678 do_action("adverts_install_module_$mod");
679
680 }
681 }
682 }
683
684 /**
685 * Activation Filter
686 *
687 * This function is run when Adverts is activated.
688 *
689 * @since 0.1
690 * @return void
691 */
692 function adverts_activate() {
693
694 // on activation ALWAYS do this
695 global $wp_rewrite;
696
697 add_option( "adverts_delayed_install", "yes");
698
699 // on FIRST activation do this.
700 if(get_option("adverts_first_run", "1") == "0") {
701 return;
702 }
703
704 // make sure this will not be ran again.
705 add_option("adverts_first_run", "0", '', false);
706
707 // register post type and taxonomy in order to allow default data insertion.
708 register_post_type( 'advert' );
709 register_taxonomy( 'advert_category', 'advert' );
710
711 wp_insert_term(
712 'Default',
713 'advert_category'
714 );
715
716 wpadverts_install_20();
717 }
718
719 /**
720 * Installator for version 2.0
721 *
722 * This function is run when WPAdverts is activated for the first time.
723 *
724 * @since 2.0
725 * @return void
726 */
727 function wpadverts_install_20() {
728
729 $hid_content = '<!-- wp:wpadverts/search {"post_type":"advert"} /-->';
730 $hid_content.= '<!-- wp:wpadverts/list {"post_type":"advert","form_scheme":""} /-->';
731
732 $hid = wp_insert_post(array(
733 'post_type' => 'page',
734 'post_status' => 'publish',
735 'post_title' => 'Classifieds',
736 'comment_status' => 'closed',
737 'ping_status' => 'closed',
738 'post_content' => $hid_content
739 ));
740
741 $aid_content = '<!-- wp:wpadverts/publish {"post_type":"advert"} /-->';
742
743 $aid = wp_insert_post(array(
744 'post_type' => 'page',
745 'post_status' => 'draft',
746 'post_title' => 'Publish',
747 'post_parent' => $hid,
748 'comment_status' => 'closed',
749 'ping_status' => 'closed',
750 'post_content' => $aid_content
751 ));
752
753 $mid_content = '<!-- wp:wpadverts/manage {"post_type":"advert"} /-->';
754
755 $mid = wp_insert_post(array(
756 'post_type' => 'page',
757 'post_status' => 'publish',
758 'post_title' => 'Manage',
759 'post_parent' => $hid,
760 'comment_status' => 'closed',
761 'ping_status' => 'closed',
762 'post_content' => $mid_content
763 ));
764
765 if( get_option( "wpadverts_block_templates_global_method" ) === false ) {
766 add_option( "wpadverts_block_templates_global_method", "block" );
767 }
768
769 if( is_int( $hid ) ) {
770 $option = get_option( "adverts_config" );
771
772 if( is_array( $option ) ) {
773 $option["ads_list_id"] = $hid;
774 update_option( "adverts_config", $option );
775 } else {
776 add_option( "adverts_config", array( "ads_list_id" => $hid ) );
777 }
778 }
779 }
780
781 // Register activation function
782 register_activation_hook( __FILE__, 'adverts_activate' );
783
784 // Run Adverts
785 add_action( 'init', 'adverts_init', 5 );
786 add_action( 'rest_api_init', 'adverts_rest_api_init' );
787 add_action( 'widgets_init', 'adverts_widgets_init' );
788
789 if(is_admin() ) {
790 // Run Adverts admin only actions
791 add_action( 'init', 'adverts_init_admin' );
792 } else {
793 // Run Adverts frontend only actions
794 add_action( 'init', 'adverts_init_frontend' );
795 }
796
797