← All changes
|
modules/floating-buttons/documents/floating-buttons.php
+12
-122
4.2.3
→
3.23.0-beta5
View file →
| @@ -1,20 +1,15 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace Elementor\Modules\FloatingButtons\Documents; |
| 4 | 4 | |
| 5 | -use Elementor\Core\Base\Document; | |
| 6 | 5 | use Elementor\Core\DocumentTypes\PageBase; |
| 7 | -use Elementor\Modules\FloatingButtons\Module; | |
| 8 | 6 | use Elementor\Modules\Library\Traits\Library as Library_Trait; |
| 9 | 7 | use Elementor\Modules\FloatingButtons\Module as Floating_Buttons_Module; |
| 10 | 8 | use Elementor\Modules\PageTemplates\Module as Page_Templates_Module; |
| 11 | -use Elementor\Plugin; | |
| 12 | -use Elementor\TemplateLibrary\Source_Local; | |
| 13 | -use Elementor\Utils as ElementorUtils; | |
| 14 | 9 | |
| 15 | 10 | if ( ! defined( 'ABSPATH' ) ) { |
| 16 | - exit; // Exit if accessed directly. | |
| 11 | + exit; // Exit if accessed directly | |
| 17 | 12 | } |
| 18 | 13 | |
| 19 | 14 | class Floating_Buttons extends PageBase { |
| 20 | 15 | use Library_Trait; |
| @@ -34,31 +29,8 @@ | ||
| 34 | 29 | |
| 35 | 30 | return $properties; |
| 36 | 31 | } |
| 37 | 32 | |
| 38 | - public static function get_floating_element_type( $post_id ) { | |
| 39 | - $meta = get_post_meta( $post_id, Floating_Buttons_Module::FLOATING_ELEMENTS_TYPE_META_KEY, true ); | |
| 40 | - return $meta ? $meta : 'floating-buttons'; | |
| 41 | - } | |
| 42 | - | |
| 43 | - public static function is_editing_existing_floating_buttons_page() { | |
| 44 | - $action = ElementorUtils::get_super_global_value( $_GET, 'action' ); | |
| 45 | - $post_id = ElementorUtils::get_super_global_value( $_GET, 'post' ); | |
| 46 | - | |
| 47 | - return 'elementor' === $action && static::is_floating_buttons_type_meta_key( $post_id ); | |
| 48 | - } | |
| 49 | - | |
| 50 | - public static function is_creating_floating_buttons_page() { | |
| 51 | - $action = ElementorUtils::get_super_global_value( $_POST, 'action' ); //phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 52 | - $post_id = ElementorUtils::get_super_global_value( $_POST, 'editor_post_id' ); //phpcs:ignore WordPress.Security.NonceVerification.Missing | |
| 53 | - | |
| 54 | - return 'elementor_ajax' === $action && static::is_floating_buttons_type_meta_key( $post_id ); | |
| 55 | - } | |
| 56 | - | |
| 57 | - public static function is_floating_buttons_type_meta_key( $post_id ) { | |
| 58 | - return Module::FLOATING_BUTTONS_DOCUMENT_TYPE === get_post_meta( $post_id, Document::TYPE_META_KEY, true ); | |
| 59 | - } | |
| 60 | - | |
| 61 | 33 | public function print_content() { |
| 62 | 34 | $plugin = \Elementor\Plugin::$instance; |
| 63 | 35 | |
| 64 | 36 | if ( $plugin->preview->is_preview_mode( $this->get_main_id() ) ) { |
| @@ -103,85 +75,10 @@ | ||
| 103 | 75 | |
| 104 | 76 | return $built_with_elementor + $actions; |
| 105 | 77 | } |
| 106 | 78 | |
| 107 | - public static function get_meta_query_for_floating_buttons( string $floating_element_type ): array { | |
| 108 | - $meta_query = [ | |
| 109 | - 'relation' => 'AND', | |
| 110 | - [ | |
| 111 | - 'key' => '_elementor_conditions', | |
| 112 | - 'compare' => 'EXISTS', | |
| 113 | - ], | |
| 114 | - ]; | |
| 115 | - | |
| 116 | - if ( 'floating-buttons' === $floating_element_type ) { | |
| 117 | - $meta_query[] = [ | |
| 118 | - 'relation' => 'OR', | |
| 119 | - [ | |
| 120 | - 'key' => Module::FLOATING_ELEMENTS_TYPE_META_KEY, | |
| 121 | - 'compare' => 'NOT EXISTS', | |
| 122 | - ], | |
| 123 | - [ | |
| 124 | - 'key' => Module::FLOATING_ELEMENTS_TYPE_META_KEY, | |
| 125 | - 'value' => 'floating-buttons', | |
| 126 | - ], | |
| 127 | - ]; | |
| 128 | - } else { | |
| 129 | - $meta_query[] = [ | |
| 130 | - 'key' => Module::FLOATING_ELEMENTS_TYPE_META_KEY, | |
| 131 | - 'value' => $floating_element_type, | |
| 132 | - ]; | |
| 133 | - } | |
| 134 | - | |
| 135 | - return $meta_query; | |
| 136 | - } | |
| 137 | - | |
| 138 | - /** | |
| 139 | - * Tries to find the post id of the floating element that is set as entire site. | |
| 140 | - * If found, returns the post id, otherwise returns 0. | |
| 141 | - * | |
| 142 | - * @param string $floating_element_type | |
| 143 | - * | |
| 144 | - * @return int | |
| 145 | - */ | |
| 146 | - public static function get_set_as_entire_site_post_id( string $floating_element_type ): int { | |
| 147 | - static $types = []; | |
| 148 | - | |
| 149 | - if ( isset( $types[ $floating_element_type ] ) ) { | |
| 150 | - return $types[ $floating_element_type ]; | |
| 151 | - } | |
| 152 | - | |
| 153 | - $query = new \WP_Query( [ | |
| 154 | - 'post_type' => Floating_Buttons_Module::CPT_FLOATING_BUTTONS, | |
| 155 | - 'posts_per_page' => -1, | |
| 156 | - 'post_status' => 'publish', | |
| 157 | - 'fields' => 'ids', | |
| 158 | - 'no_found_rows' => true, | |
| 159 | - 'update_post_term_cache' => false, | |
| 160 | - 'meta_query' => static::get_meta_query_for_floating_buttons( $floating_element_type ), | |
| 161 | - ] ); | |
| 162 | - | |
| 163 | - foreach ( $query->get_posts() as $post_id ) { | |
| 164 | - $conditions = get_post_meta( $post_id, '_elementor_conditions', true ); | |
| 165 | - | |
| 166 | - if ( ! $conditions ) { | |
| 167 | - continue; | |
| 168 | - } | |
| 169 | - | |
| 170 | - if ( in_array( 'include/general', $conditions ) ) { | |
| 171 | - $types[ $floating_element_type ] = $post_id; | |
| 172 | - return $post_id; | |
| 173 | - } | |
| 174 | - } | |
| 175 | - | |
| 176 | - return 0; | |
| 177 | - } | |
| 178 | - | |
| 179 | 79 | public function set_as_entire_site( $actions ) { |
| 180 | - $floating_element_type = static::get_floating_element_type( $this->get_main_id() ); | |
| 181 | - $current_set_as_entire_site_post_id = static::get_set_as_entire_site_post_id( $floating_element_type ); | |
| 182 | - | |
| 183 | - if ( $current_set_as_entire_site_post_id === $this->get_main_id() ) { | |
| 80 | + if ( get_post_meta( $this->get_post()->ID, '_elementor_conditions', true ) ) { | |
| 184 | 81 | $actions['set_as_entire_site'] = sprintf( |
| 185 | 82 | '<a style="color:red;" href="?post=%s&action=remove_from_entire_site&_wpnonce=%s">%s</a>', |
| 186 | 83 | $this->get_post()->ID, |
| 187 | 84 | wp_create_nonce( 'remove_from_entire_site_' . $this->get_post()->ID ), |
| @@ -199,13 +96,13 @@ | ||
| 199 | 96 | return $actions; |
| 200 | 97 | } |
| 201 | 98 | |
| 202 | 99 | public static function get_title() { |
| 203 | - return esc_html__( 'Floating Element', 'elementor' ); | |
| 100 | + return esc_html__( 'Floating Button', 'elementor' ); | |
| 204 | 101 | } |
| 205 | 102 | |
| 206 | 103 | public static function get_plural_title() { |
| 207 | - return esc_html__( 'Floating Elements', 'elementor' ); | |
| 104 | + return esc_html__( 'Floating Buttons', 'elementor' ); | |
| 208 | 105 | } |
| 209 | 106 | |
| 210 | 107 | public static function get_create_url() { |
| 211 | 108 | return parent::get_create_url() . '#library'; |
| @@ -220,27 +117,20 @@ | ||
| 220 | 117 | } |
| 221 | 118 | |
| 222 | 119 | public function admin_columns_content( $column_name ) { |
| 223 | 120 | if ( 'elementor_library_type' === $column_name ) { |
| 224 | - $admin_filter_url = admin_url( Source_Local::ADMIN_MENU_SLUG . '&elementor_library_type=' . $this->get_name() ); | |
| 225 | - $meta = static::get_floating_element_type( $this->get_main_id() ); | |
| 226 | - printf( '<a href="%s">%s</a>', $admin_filter_url, Module::get_floating_elements_types()[ $meta ] ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 121 | + $this->print_admin_column_type(); | |
| 227 | 122 | } |
| 228 | 123 | } |
| 229 | 124 | |
| 230 | 125 | public function get_edit_url() { |
| 231 | - return add_query_arg( | |
| 232 | - [ | |
| 233 | - 'post' => $this->get_main_id(), | |
| 234 | - 'action' => 'elementor', | |
| 235 | - 'floating_element' => get_post_meta( | |
| 236 | - $this->get_main_id(), | |
| 237 | - Module::FLOATING_ELEMENTS_TYPE_META_KEY, | |
| 238 | - true | |
| 239 | - ), | |
| 240 | - ], | |
| 241 | - admin_url( 'post.php' ) | |
| 242 | - ); | |
| 126 | + $url = parent::get_edit_url(); | |
| 127 | + | |
| 128 | + if ( ! $this->get_post()->post_content ) { | |
| 129 | + $url .= '#library'; | |
| 130 | + } | |
| 131 | + | |
| 132 | + return $url; | |
| 243 | 133 | } |
| 244 | 134 | |
| 245 | 135 | protected function get_remote_library_config() { |
| 246 | 136 | $config = [ |