Plugin Directory

Changeset 3245097


Ignore:
Timestamp:
02/23/2025 12:38:24 AM (13 months ago)
Author:
jkplugins
Message:

upgrade to 1.2.1 / fix missing files in svn

Location:
menu-manager-ultra/trunk
Files:
38 added
3 edited

Legend:

Unmodified
Added
Removed
  • menu-manager-ultra/trunk/menu-manager-ultra.php

    r3245090 r3245097  
    11<?php
    2 
    32/**
    43 * Menu Manager Ultra
     
    1110 * Requires at least: 5.8
    1211 * Requires PHP:      7.0
    13  * Version:           1.2.0
     12 * Version:           1.2.1
    1413 * Author:            JK Plugins
    1514 * Text Domain:       mm_ultra
     
    1817 * @package           jk-plugins
    1918 */
     19
    2020require __DIR__ . '/vendor/autoload.php';
    21 $this_dir_base_path = dirname( __FILE__ ) . DIRECTORY_SEPARATOR;
    22 require_once $this_dir_base_path . 'src' . DIRECTORY_SEPARATOR . 'util' . DIRECTORY_SEPARATOR . 'constants.php';
    23 require_once $this_dir_base_path . 'src' . DIRECTORY_SEPARATOR . 'util' . DIRECTORY_SEPARATOR . 'menu-manager-array-utils.php';
    24 require_once $this_dir_base_path . DIRECTORY_SEPARATOR . 'menu-manager-routes.php';
     21
     22
     23$this_dir_base_path = dirname(__FILE__). DIRECTORY_SEPARATOR;
     24
     25require_once($this_dir_base_path . 'src' . DIRECTORY_SEPARATOR . 'util' . DIRECTORY_SEPARATOR . 'constants.php');
     26require_once($this_dir_base_path . 'src' . DIRECTORY_SEPARATOR . 'util' . DIRECTORY_SEPARATOR . 'menu-manager-array-utils.php');
     27require_once($this_dir_base_path . DIRECTORY_SEPARATOR . 'menu-manager-routes.php');
     28
    2529add_action( 'admin_menu', 'mmultra_init_menu' );
     30
    2631/**
    2732 * Init Admin Menu.
     
    3035 */
    3136function mmultra_init_menu() {
    32     add_theme_page(
    33         "Menu Manager Ultra",
    34         "Menu Manager Ultra",
    35         'edit_theme_options',
    36         'menu-manager-ultra',
    37         'mmultra_admin_page'
    38     );
     37
     38  add_theme_page(
     39    "Menu Manager Ultra",
     40    "Menu Manager Ultra",
     41    'edit_theme_options',
     42    'menu-manager-ultra',
     43    'mmultra_admin_page'
     44  );
     45
    3946}
    4047
     
    4956
    5057add_action( 'admin_enqueue_scripts', 'mmultra_admin_enqueue_scripts' );
     58
    5159/**
    5260 * Enqueue scripts and styles.
     
    5765    wp_enqueue_style( 'mm-ultra-style', plugin_dir_url( __FILE__ ) . 'build/main.css' );
    5866    wp_enqueue_script(
    59         'mm-ultra-script',
    60         plugin_dir_url( __FILE__ ) . 'build/index.js',
     67        'mm-ultra-script', plugin_dir_url( __FILE__ ) . 'build/index.js',
    6168        array('wp-element', 'wp-api-fetch'),
    62         '1.0.0',
    63         true
     69        '1.0.0', true
    6470    );
    6571}
     
    6975 */
    7076function mmultra_custom_post_types() {
    71     register_post_type( 'mmu_revision', array(
    72         'labels'       => array(
    73             'name'          => __( 'Menu Revisions' ),
    74             'singular_name' => __( 'Menu Revision' ),
    75         ),
    76         'public'       => false,
    77         'has_archive'  => false,
    78         'show_in_rest' => true,
    79     ) );
     77 
     78  register_post_type( 'mmu_revision',
     79      array(
     80          'labels' => array(
     81              'name' => __( 'Menu Revisions' ),
     82              'singular_name' => __( 'Menu Revision' )
     83          ),
     84          'public' => false,
     85          'has_archive' => false,
     86          'show_in_rest' => true,
     87
     88      )
     89  );
    8090}
    8191
    8292add_action( 'init', 'mmultra_custom_post_types' );
     93
    8394/**
    8495 * Freemius integration code
    8596 */
    86 if ( !function_exists( 'mmultra_fs' ) ) {
    87     // Create a helper function for easy SDK access.
    88     function mmultra_fs() {
    89         global $mmultra_fs;
    90         if ( !isset( $mmultra_fs ) ) {
    91             // Include Freemius SDK.
    92             require_once dirname( __FILE__ ) . '/freemius/start.php';
    93             $mmultra_fs = fs_dynamic_init( array(
    94                 'id'             => '11982',
     97if ( ! function_exists( 'mmultra_fs' ) ) {
     98  // Create a helper function for easy SDK access.
     99  function mmultra_fs() {
     100      global $mmultra_fs;
     101
     102      if ( ! isset( $mmultra_fs ) ) {
     103          // Include Freemius SDK.
     104          require_once dirname(__FILE__) . '/freemius/start.php';
     105
     106          $mmultra_fs = fs_dynamic_init( array(
     107            'id'                  => '11982',
     108            'slug'                => 'menu-manager-ultra',
     109            'type'                => 'plugin',
     110            'public_key'          => 'pk_a6319041fb80c1585655b9be45407',
     111            'is_premium'          => true,
     112            'premium_suffix'      => 'Pro',
     113            // If your plugin is a serviceware, set this option to false.
     114            'has_premium_version' => true,
     115            'has_addons'          => false,
     116            'has_paid_plans'      => true,
     117            'trial'               => array(
     118                'days'               => 14,
     119                'is_require_payment' => false,
     120            ),
     121            'menu'                => array(
    95122                'slug'           => 'menu-manager-ultra',
    96                 'type'           => 'plugin',
    97                 'public_key'     => 'pk_a6319041fb80c1585655b9be45407',
    98                 'is_premium'     => false,
    99                 'premium_suffix' => 'Pro',
    100                 'has_addons'     => false,
    101                 'has_paid_plans' => true,
    102                 'trial'          => array(
    103                     'days'               => 14,
    104                     'is_require_payment' => false,
     123                'support'        => false,
     124                'parent'         => array(
     125                    'slug' => 'themes.php',
    105126                ),
    106                 'menu'           => array(
    107                     'slug'    => 'menu-manager-ultra',
    108                     'support' => false,
    109                     'parent'  => array(
    110                         'slug' => 'themes.php',
    111                     ),
    112                 ),
    113                 'is_live'        => true,
    114             ) );
    115         }
    116         return $mmultra_fs;
    117     }
     127            ),
     128              // Set the SDK to work in a sandbox mode (for development & testing).
     129              // IMPORTANT: MAKE SURE TO REMOVE SECRET KEY BEFORE DEPLOYMENT.
     130              'secret_key'          => '02bde5c1c82defa33991f01dbad5f00e',
     131          ) );
     132      }
    118133
    119     // Init Freemius.
    120     mmultra_fs();
    121     // Signal that SDK was initiated.
    122     do_action( 'mmultra_fs_loaded' );
    123     function mmultra_add_licensing_helper() {
    124         echo '<script type="text/javascript">
     134      return $mmultra_fs;
     135  }
     136
     137  // Init Freemius.
     138  mmultra_fs();
     139  // Signal that SDK was initiated.
     140  do_action( 'mmultra_fs_loaded' );
     141
     142  function mmultra_add_licensing_helper() {
     143    echo '<script type="text/javascript">
    125144        (function(){
    126145            window.MMU = {};
    127             window.MMU.upgrade_url = ' . json_encode( mmultra_fs()->get_upgrade_url() ) . ';
     146            window.MMU.upgrade_url = ' . json_encode(mmultra_fs()->get_upgrade_url()) . ';
    128147            window.MMU.can_use_premium_code = ' . json_encode( mmultra_fs()->can_use_premium_code() ) . ';
    129148        })();
    130149    </script>';
    131     }
     150  }
     151 
     152  add_action('admin_head', 'mmultra_add_licensing_helper');
     153}
    132154
    133     add_action( 'admin_head', 'mmultra_add_licensing_helper' );
    134 }
     155
  • menu-manager-ultra/trunk/readme.txt

    r3245090 r3245097  
    1212License: GPLv3 or later
    1313License URI: http://www.gnu.org/licenses/gpl-3.0.html
    14 Stable tag: 1.2.0
     14Stable tag: 1.2.1
    1515
    1616Better menu management for administrators. Works with very large menus and custom page types
  • menu-manager-ultra/trunk/src/API/Endpoints/Posts.php

    r3245090 r3245097  
    66use MenuManagerUltra\lib\Post\PostDataFormatter;
    77use MenuManagerUltra\lib\Constants;
     8
    89class Posts extends \WP_REST_Controller {
    9     public function register_routes() {
    10         register_rest_route( Constants::ROUTE_BASE, '/posts/search', array(
    11             'methods'             => 'POST',
    12             'callback'            => [$this, 'searchPosts'],
    13             'permission_callback' => function ( $request ) {
    14                 return current_user_can( Constants::ENDPOINT_PERMISSION_DEFAULT );
    15             },
    16         ) );
    17         register_rest_route( Constants::ROUTE_BASE, '/posts/types', array(
    18             'methods'             => 'GET',
    19             'callback'            => [$this, 'getPostTypesAsObjects'],
    20             'permission_callback' => function ( $request ) {
    21                 return current_user_can( Constants::ENDPOINT_PERMISSION_DEFAULT );
    22             },
    23         ) );
    24         register_rest_route( Constants::ROUTE_BASE, '/post/(?P<post_id>\\d+)/get', array(
    25             'methods'             => 'GET',
    26             'callback'            => [$this, 'getPost'],
    27             'args'                => array(
    28                 'post_id' => array(
    29                     'validate_callback' => function ( $param, $request, $key ) {
    30                         return is_numeric( $param );
    31                     },
    32                 ),
    33             ),
    34             'permission_callback' => function ( $request ) {
    35                 return current_user_can( Constants::ENDPOINT_PERMISSION_DEFAULT );
    36             },
    37         ) );
     10
     11  public function register_routes() {
     12
     13    register_rest_route( Constants::ROUTE_BASE, '/posts/search', array(
     14      'methods' => 'POST',
     15      'callback' => [$this, 'searchPosts'],
     16      'permission_callback' => function($request) {
     17        return current_user_can(Constants::ENDPOINT_PERMISSION_DEFAULT);
     18      }
     19    ) );
     20
     21    register_rest_route( Constants::ROUTE_BASE, '/posts/types', array(
     22      'methods' => 'GET',
     23      'callback' => [$this, 'getPostTypesAsObjects'],
     24      'permission_callback' => function($request) {
     25        return current_user_can(Constants::ENDPOINT_PERMISSION_DEFAULT);
     26      }
     27    ) );
     28 
     29    register_rest_route( Constants::ROUTE_BASE, '/post/(?P<post_id>\d+)/get', array(
     30      'methods' => 'GET',
     31      'callback' => [$this, 'getPost'],
     32      'args' => array(
     33        'post_id' => array(
     34          'validate_callback' => function($param, $request, $key) {
     35            return is_numeric( $param );
     36          }
     37        ),
     38      ),
     39      'permission_callback' => function($request) {
     40        return current_user_can(Constants::ENDPOINT_PERMISSION_DEFAULT);
     41      }
     42    ) );
     43  }
     44
     45  /*
     46  * Used as a filter for WP_Query to search title & content because certain plugins/hooks
     47  * can upset the use of the "s" parameter
     48  */
     49  public function applySearchParamToQuery($where, $wp_query) {
     50    global $wpdb;
     51   
     52    if ( $search_keys = $wp_query->get('mmu_search_query') ) {
     53      $where .= " AND
     54        (
     55            {$wpdb->posts}.post_title LIKE '%" . esc_sql($search_keys) . "%'
     56        OR
     57            {$wpdb->posts}.post_content LIKE '%" . esc_sql($search_keys) . "%'
     58        )" ;
    3859    }
    3960
    40     /*
    41      * Used as a filter for WP_Query to search title & content because certain plugins/hooks
    42      * can upset the use of the "s" parameter
    43      */
    44     public function applySearchParamToQuery( $where, $wp_query ) {
    45         global $wpdb;
    46         if ( $search_keys = $wp_query->get( 'mmu_search_query' ) ) {
    47             $where .= " AND\n        (\n            {$wpdb->posts}.post_title LIKE '%" . esc_sql( $search_keys ) . "%'\n        OR\n            {$wpdb->posts}.post_content LIKE '%" . esc_sql( $search_keys ) . "%'\n        )";
     61    return $where;
     62  }
     63
     64  public function searchPosts($params) {
     65
     66    add_filter( 'posts_where', [$this, 'applySearchParamToQuery'], 10, 2);
     67
     68    $post_types = $this->getPostTypes('names');
     69    $num_per_page = 20;
     70    $page_number = 0;
     71 
     72    if (isset($params['offset']) && $params['offset'] > 0) {
     73      $page_number = (ceil($params['offset'] / $num_per_page) + 1);
     74    }
     75 
     76    $args = [
     77      'mmu_search_query' => $params['search_key']
     78    ];
     79
     80    if (!empty($params['type_filter'])) {
     81      $args['post_type'] = $params['type_filter'];
     82    }
     83    else {
     84      $args['post_type'] = $post_types;
     85    }
     86     
     87    /* Query the results for the given search keywords */
     88    $results_query = new \WP_Query(
     89      array_merge(
     90        $args, [
     91          'posts_per_page' => $num_per_page,
     92          'paged' => $page_number,
     93        ]
     94      )
     95    );
     96 
     97    $results = $results_query->get_posts();
     98 
     99    /* Loop through the results and add in the permalink */
     100    $results = array_map(
     101      function($result) {
     102        return PostDataFormatter::normalizePostData($result->ID, $result);
     103      },
     104      $results
     105    );
     106 
     107    /* Issue a query to count all matching results, regardless of pagination */
     108    $count_query = new \WP_Query(
     109      array_merge($args, [
     110      'posts_per_page' => -1,
     111      'fields' => 'ids',
     112      ])
     113    );
     114 
     115    $num_results = intval($count_query->found_posts);
     116 
     117    return [
     118      'total_results' => $num_results,
     119      'results' => $results
     120    ];
     121  }
     122
     123  public function getPostTypesAsObjects() {
     124    return $this->getPostTypes('objects');
     125  }
     126
     127  public function getPostTypes( $return_type = 'objects' ) {
     128 
     129    $args = [
     130      'public' => true,
     131      'show_in_nav_menus' => 1
     132    ];
     133 
     134    $types = get_post_types( $args, $return_type );
     135   
     136    if ($return_type == 'objects') {
     137      $ret = [];
     138 
     139      foreach ($types as $name => $obj) {
     140 
     141        /* @TODO Move this to PostDataFormatter */
     142        $obj->type_slug = $name;
     143        $obj->labels = get_post_type_labels($obj);
     144        $obj->display_title = $obj->labels->singular_name;
     145       
     146
     147        $ret[] = $obj;
     148      }
     149 
     150    }
     151    else {
     152      $ret = $types;
     153    }
     154 
     155    return $this->postTypesApplyPremiumFilter($ret);
     156 
     157  }
     158
     159  public function postTypesApplyPremiumFilter($types) {
     160 
     161    if ( mmultra_fs()->can_use_premium_code__premium_only() ) {
     162      return $types;
     163    }
     164 
     165    return array_filter(
     166      $types,
     167      function($val) {
     168        if (is_object($val)) {
     169          if (!empty($val->name)) {
     170            return in_array($val->name, Constants::POST_TYPES_FREE);
     171          }
     172          else {
     173            return false;
     174          }
    48175        }
    49         return $where;
     176        else {
     177          return in_array($val, Constants::POST_TYPES_FREE);
     178        }
     179      }
     180    );
     181  }
     182 
     183  public function getPost($params) {
     184 
     185    $post = null;
     186 
     187    if ($post = get_post($params['post_id'])) {
     188 
     189      $post = PostDataFormatter::applyLinks($post);
     190      $post->labels = get_post_type_labels($post);
    50191    }
     192   
     193    return ['post' => $post];
     194  }
     195 
     196}
    51197
    52     public function searchPosts( $params ) {
    53         add_filter(
    54             'posts_where',
    55             [$this, 'applySearchParamToQuery'],
    56             10,
    57             2
    58         );
    59         $post_types = $this->getPostTypes( 'names' );
    60         $num_per_page = 20;
    61         $page_number = 0;
    62         if ( isset( $params['offset'] ) && $params['offset'] > 0 ) {
    63             $page_number = ceil( $params['offset'] / $num_per_page ) + 1;
    64         }
    65         $args = [
    66             'mmu_search_query' => $params['search_key'],
    67         ];
    68         if ( !empty( $params['type_filter'] ) ) {
    69             $args['post_type'] = $params['type_filter'];
    70         } else {
    71             $args['post_type'] = $post_types;
    72         }
    73         /* Query the results for the given search keywords */
    74         $results_query = new \WP_Query(array_merge( $args, [
    75             'posts_per_page' => $num_per_page,
    76             'paged'          => $page_number,
    77         ] ));
    78         $results = $results_query->get_posts();
    79         /* Loop through the results and add in the permalink */
    80         $results = array_map( function ( $result ) {
    81             return PostDataFormatter::normalizePostData( $result->ID, $result );
    82         }, $results );
    83         /* Issue a query to count all matching results, regardless of pagination */
    84         $count_query = new \WP_Query(array_merge( $args, [
    85             'posts_per_page' => -1,
    86             'fields'         => 'ids',
    87         ] ));
    88         $num_results = intval( $count_query->found_posts );
    89         return [
    90             'total_results' => $num_results,
    91             'results'       => $results,
    92         ];
    93     }
    94 
    95     public function getPostTypesAsObjects() {
    96         return $this->getPostTypes( 'objects' );
    97     }
    98 
    99     public function getPostTypes( $return_type = 'objects' ) {
    100         $args = [
    101             'public'            => true,
    102             'show_in_nav_menus' => 1,
    103         ];
    104         $types = get_post_types( $args, $return_type );
    105         if ( $return_type == 'objects' ) {
    106             $ret = [];
    107             foreach ( $types as $name => $obj ) {
    108                 /* @TODO Move this to PostDataFormatter */
    109                 $obj->type_slug = $name;
    110                 $obj->labels = get_post_type_labels( $obj );
    111                 $obj->display_title = $obj->labels->singular_name;
    112                 $ret[] = $obj;
    113             }
    114         } else {
    115             $ret = $types;
    116         }
    117         return $this->postTypesApplyPremiumFilter( $ret );
    118     }
    119 
    120     public function postTypesApplyPremiumFilter( $types ) {
    121         return array_filter( $types, function ( $val ) {
    122             if ( is_object( $val ) ) {
    123                 if ( !empty( $val->name ) ) {
    124                     return in_array( $val->name, Constants::POST_TYPES_FREE );
    125                 } else {
    126                     return false;
    127                 }
    128             } else {
    129                 return in_array( $val, Constants::POST_TYPES_FREE );
    130             }
    131         } );
    132     }
    133 
    134     public function getPost( $params ) {
    135         $post = null;
    136         if ( $post = get_post( $params['post_id'] ) ) {
    137             $post = PostDataFormatter::applyLinks( $post );
    138             $post->labels = get_post_type_labels( $post );
    139         }
    140         return [
    141             'post' => $post,
    142         ];
    143     }
    144 
    145 }
Note: See TracChangeset for help on using the changeset viewer.