PluginProbe ʕ •ᴥ•ʔ
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz / 2.12.3
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz v2.12.3
2.12.5 2.12.4 2.12.3 2.12.2 2.12.1 2.12.0 2.11.1 2.11.0 2.10.1 2.10.0 2.9.1 2.9.0 2.8.2 2.8.1 2.7.0 2.7.1 2.8.0 trunk 0.0.10 0.0.11 0.0.12 0.0.13 0.0.2 0.0.3 0.0.4 0.0.5 0.0.6 0.0.7 0.0.8 0.0.9 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.1.0 1.1.1 1.1.2 1.10.0 1.10.1 1.11.0 1.12.0 1.12.1 1.12.2 1.12.3 1.13.0 1.13.1 1.13.2 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.3.0 1.3.1 1.3.2 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.5.0 1.5.1 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.7.0 1.7.1 1.7.2 1.7.3 1.7.4 1.8.0 1.9.0 1.9.1 2.0.0 2.0.1 2.0.2 2.1.0 2.1.1 2.2.0 2.2.1 2.2.2 2.3.0 2.4.0 2.5.0 2.5.2 2.6.0
sureforms / inc / compatibility / themes / astra.php
sureforms / inc / compatibility / themes Last commit date
astra.php 1 year ago
astra.php
90 lines
1 <?php
2 /**
3 * Astra Compatibility.
4 *
5 * @package sureforms
6 * @since 1.6.1
7 */
8
9 namespace SRFM\Inc\Compatibility\Themes;
10
11 use SRFM\Inc\Helper;
12 use SRFM\Inc\Traits\Get_Instance;
13
14 // Exit if accessed directly.
15 defined( 'ABSPATH' ) || exit;
16
17 /**
18 * Sureforms Astra Compatibility.
19 *
20 * @since 1.6.1
21 */
22 class Astra {
23 use Get_Instance;
24
25 /**
26 * Constructor
27 *
28 * @since 1.6.1
29 */
30 public function __construct() {
31 // Update Astra's menu priority to show after Dashboard menu.
32 add_filter( 'astra_menu_priority', [ $this, 'update_admin_menu_position' ], 99999, 1 );
33 }
34
35 /**
36 * Update Astra's menu priority to show after Dashboard menu.
37 * Checks for existing menu items and assigns a new priority to Astra's menu item.
38 *
39 * @param int $astra_priority Astra menu priority.
40 *
41 * @return float
42 * @since 1.6.1
43 */
44 public function update_admin_menu_position( $astra_priority ) {
45 global $menu;
46
47 $dashboard_priority = null;
48
49 // Loop through the menu items to find the dashboard priority.
50 foreach ( $menu as $position => $menu_item ) {
51 // We are checking at index 5 because it is the position of the menu-dashboard slug and it is not affected by translation.
52 if ( isset( $menu_item[5] ) && 'menu-dashboard' === $menu_item[5] ) {
53 $dashboard_priority = (float) $position;
54 break;
55 }
56 }
57
58 // If we couldn't find the dashboard priority, set it to 2.0.
59 if ( null === $dashboard_priority ) {
60 $dashboard_priority = 2.0;
61 }
62
63 // Check if the Astra priority is numeric.
64 // If not, set it to 2.0.
65 if ( ! is_numeric( $astra_priority ) ) {
66 $astra_priority = 2.0;
67 } else {
68 $astra_priority = (float) $astra_priority;
69 }
70
71 // If the Astra priority is already less than the dashboard priority, return it.
72 if ( $astra_priority < $dashboard_priority ) {
73 return $astra_priority;
74 }
75
76 // Increase the Astra priority by 0.1 so that it is placed right after the Dashboard.
77 $astra_priority = $dashboard_priority + 0.1;
78
79 $existing_priorities = array_keys( $menu );
80
81 // If the computed astra_priority already exists, just default to 2.0.
82 // We are converting the existing priorities to string to make sure the type is always same.
83 if ( in_array( Helper::get_string_value( $astra_priority ), array_map( 'strval', $existing_priorities ), true ) ) {
84 $astra_priority = 2.0;
85 }
86
87 return $astra_priority;
88 }
89 }
90