← All changes
|
integrations/shortlinkspro/includes/functions.php
+161
-0
5.7.9.2
→
6.0.3
View file →
| @@ -1,0 +1,161 @@ | ||
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * Functions | |
| 4 | + * | |
| 5 | + * @package AutomatorWP\ShortLinksPro\Functions | |
| 6 | + * @since 1.0.0 | |
| 7 | + */ | |
| 8 | +// Exit if accessed directly | |
| 9 | +if( !defined( 'ABSPATH' ) ) exit; | |
| 10 | + | |
| 11 | +/** | |
| 12 | + * Options callback for select2 fields assigned to links | |
| 13 | + * | |
| 14 | + * @since 1.0.0 | |
| 15 | + * | |
| 16 | + * @param stdClass $field | |
| 17 | + * | |
| 18 | + * @return array | |
| 19 | + */ | |
| 20 | +function automatorwp_shortlinkspro_options_cb_link( $field ) { | |
| 21 | + | |
| 22 | + // Setup vars | |
| 23 | + $value = $field->escaped_value; | |
| 24 | + $none_value = 'any'; | |
| 25 | + $none_label = __( 'any link', 'automatorwp' ); | |
| 26 | + $options = automatorwp_options_cb_none_option( $field, $none_value, $none_label ); | |
| 27 | + | |
| 28 | + if( ! empty( $value ) ) { | |
| 29 | + if( ! is_array( $value ) ) { | |
| 30 | + $value = array( $value ); | |
| 31 | + } | |
| 32 | + | |
| 33 | + foreach( $value as $link_id ) { | |
| 34 | + | |
| 35 | + // Skip option none | |
| 36 | + if( $link_id === $none_value ) { | |
| 37 | + continue; | |
| 38 | + } | |
| 39 | + | |
| 40 | + $options[$link_id] = shortlinkspro_get_link_title( $link_id ); | |
| 41 | + } | |
| 42 | + } | |
| 43 | + | |
| 44 | + return $options; | |
| 45 | +} | |
| 46 | + | |
| 47 | +/** | |
| 48 | + * Options callback for select2 fields assigned to categories | |
| 49 | + * | |
| 50 | + * @since 1.0.0 | |
| 51 | + * | |
| 52 | + * @param stdClass $field | |
| 53 | + * | |
| 54 | + * @return array | |
| 55 | + */ | |
| 56 | +function automatorwp_shortlinkspro_options_cb_category( $field ) { | |
| 57 | + | |
| 58 | + // Setup vars | |
| 59 | + $value = $field->escaped_value; | |
| 60 | + $none_value = 'any'; | |
| 61 | + $none_label = __( 'any category', 'automatorwp' ); | |
| 62 | + $options = automatorwp_options_cb_none_option( $field, $none_value, $none_label ); | |
| 63 | + | |
| 64 | + if( ! empty( $value ) ) { | |
| 65 | + if( ! is_array( $value ) ) { | |
| 66 | + $value = array( $value ); | |
| 67 | + } | |
| 68 | + | |
| 69 | + foreach( $value as $category_id ) { | |
| 70 | + | |
| 71 | + // Skip option none | |
| 72 | + if( $category_id === $none_value ) { | |
| 73 | + continue; | |
| 74 | + } | |
| 75 | + | |
| 76 | + $options[$category_id] = shortlinkspro_get_link_category_name( $category_id ); | |
| 77 | + } | |
| 78 | + } | |
| 79 | + | |
| 80 | + return $options; | |
| 81 | +} | |
| 82 | + | |
| 83 | +/** | |
| 84 | + * Options callback for select2 fields assigned to tags | |
| 85 | + * | |
| 86 | + * @since 1.0.0 | |
| 87 | + * | |
| 88 | + * @param stdClass $field | |
| 89 | + * | |
| 90 | + * @return array | |
| 91 | + */ | |
| 92 | +function automatorwp_shortlinkspro_options_cb_tag( $field ) { | |
| 93 | + | |
| 94 | + // Setup vars | |
| 95 | + $value = $field->escaped_value; | |
| 96 | + $none_value = 'any'; | |
| 97 | + $none_label = __( 'any tag', 'automatorwp' ); | |
| 98 | + $options = automatorwp_options_cb_none_option( $field, $none_value, $none_label ); | |
| 99 | + | |
| 100 | + if( ! empty( $value ) ) { | |
| 101 | + if( ! is_array( $value ) ) { | |
| 102 | + $value = array( $value ); | |
| 103 | + } | |
| 104 | + | |
| 105 | + foreach( $value as $tag_id ) { | |
| 106 | + | |
| 107 | + // Skip option none | |
| 108 | + if( $tag_id === $none_value ) { | |
| 109 | + continue; | |
| 110 | + } | |
| 111 | + | |
| 112 | + $options[$tag_id] = shortlinkspro_get_link_tag_name( $tag_id ); | |
| 113 | + } | |
| 114 | + } | |
| 115 | + | |
| 116 | + return $options; | |
| 117 | +} | |
| 118 | + | |
| 119 | +/** | |
| 120 | + * Get categories related to link | |
| 121 | + * | |
| 122 | + * @since 1.0.0 | |
| 123 | + * | |
| 124 | + * @param int $link_id | |
| 125 | + * | |
| 126 | + * @return object | |
| 127 | + */ | |
| 128 | +function automatorwp_shortlinkspro_get_categories_from_link( $link_id ) { | |
| 129 | + | |
| 130 | + global $wpdb; | |
| 131 | + | |
| 132 | + // Get categories related to link | |
| 133 | + ct_setup_table( 'shortlinkspro_link_categories_relationships' ); | |
| 134 | + $categories = ct_get_object_terms( $link_id ); | |
| 135 | + ct_reset_setup_table(); | |
| 136 | + | |
| 137 | + return $categories; | |
| 138 | + | |
| 139 | +} | |
| 140 | + | |
| 141 | +/** | |
| 142 | + * Get tags related to link | |
| 143 | + * | |
| 144 | + * @since 1.0.0 | |
| 145 | + * | |
| 146 | + * @param int $link_id | |
| 147 | + * | |
| 148 | + * @return object | |
| 149 | + */ | |
| 150 | +function automatorwp_shortlinkspro_get_tags_from_link( $link_id ) { | |
| 151 | + | |
| 152 | + global $wpdb; | |
| 153 | + | |
| 154 | + // Get tags related to link | |
| 155 | + ct_setup_table( 'shortlinkspro_link_tags_relationships' ); | |
| 156 | + $tags = ct_get_object_terms( $link_id ); | |
| 157 | + ct_reset_setup_table(); | |
| 158 | + | |
| 159 | + return $tags; | |
| 160 | + | |
| 161 | +} | |