PluginProbe
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI / 6.0.3
AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI v6.0.3
6.0.3 6.0.2 6.0.1 6.0.0 5.8.6 5.8.5 5.8.4 5.8.3 5.8.2 5.8.1 5.8.0 5.7.9.2 5.7.9.1 5.7.8 5.7.9 5.7.6 5.7.7 5.7.5 5.7.4 5.7.3 5.7.2 5.7.1 trunk 5.6.0 5.6.1 All 34 releases
automatorwp / integrations / gamipress / includes / functions.php

functions.php in AutomatorWP – No-Code Workflow Automation, Integration & Webhooks Plugin, now with AI 6.0.3, at integrations/gamipress/includes/functions.php

102 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Functions
4 *
5 * @package AutomatorWP\Integrations\GamiPress\Functions
6 * @author AutomatorWP <[email protected]>, Ruben Garcia <[email protected]>
7 * @since 1.0.0
8 */
9 // Exit if accessed directly
10 if( !defined( 'ABSPATH' ) ) exit;
11
12 /**
13 * Options callback for select fields assigned to points types
14 *
15 * @since 1.0.0
16 *
17 * @param stdClass $field
18 *
19 * @return array
20 */
21 function automatorwp_gamipress_points_types_options_cb( $field ) {
22
23 // Setup vars
24 $value = $field->escaped_value;
25 $none_value = 'any';
26 $none_label = __( 'any points type', 'automatorwp' );
27 $options = automatorwp_options_cb_none_option( $field, $none_value, $none_label );
28
29 foreach( gamipress_get_points_types() as $points_type => $data ) {
30 $options[$points_type] = $data['plural_name'];
31 }
32
33 return $options;
34
35 }
36
37 /**
38 * Switch to main site if GamiPress is network wide active
39 *
40 * @since 1.0.0
41 */
42 function automatorwp_gamipress_ajax_get_posts() {
43
44 if( isset( $_REQUEST['post_type_cb'] ) ) {
45
46 $post_type_cb = sanitize_text_field( $_REQUEST['post_type_cb'] );
47 $gamipress_cbs = array( 'gamipress_get_points_types_slugs', 'gamipress_get_achievement_types_slugs', 'gamipress_get_rank_types_slugs' );
48
49 // If is any of the GamiPress post types
50 if( in_array( $post_type_cb, $gamipress_cbs ) ) {
51 gamipress_switch_to_main_site_if_network_wide_active();
52 }
53
54 }
55
56 }
57 add_action( 'wp_ajax_automatorwp_get_posts', 'automatorwp_gamipress_ajax_get_posts', 1 );
58
59 /**
60 * Utility function to get the post option parameter
61 *
62 * @since 1.0.0
63 *
64 * @param array $args
65 *
66 * @return array
67 */
68 function automatorwp_gamipress_utilities_post_option( $args = array() ) {
69
70 $post_options = automatorwp_utilities_post_option( $args );
71
72 $post_options['fields']['post']['options_cb'] = 'automatorwp_gamipress_options_cb_posts';
73
74 return $post_options;
75
76 }
77
78 /**
79 * Options callback for select2 fields assigned to posts with the special condition that if is for GamiPress, requires a blog switch
80 *
81 * @since 1.0.0
82 *
83 * @param stdClass $field
84 *
85 * @return array
86 */
87 function automatorwp_gamipress_options_cb_posts( $field ) {
88
89 if( gamipress_is_network_wide_active() ) {
90 gamipress_switch_to_main_site();
91 }
92
93 $options = automatorwp_options_cb_posts( $field );
94
95 if( gamipress_is_network_wide_active() ) {
96 restore_current_blog();
97 }
98
99 return $options;
100
101 }
102