/** * Add a license page to the swifty admin pages. Do this only when the page name was initialized by an plugin that * needed this page */ public function hook_admin_menu_swifty_admin_licenses_page() { global $swifty_admin_licenses_page; if (!empty($swifty_admin_licenses_page)) { LibSwiftyPlugin::get_instance()->admin_add_swifty_menu('Licenses', __('Licenses', 'swifty'), $swifty_admin_licenses_page, array($this, 'hook_swifty_admin_license_page'), true); } }
/** * Check if swiftylib classes are needed and find newest version of lib before instantiating * * @param $class_name */ function swifty_autoload_function($class_name) { if ($class_name === 'LibSwiftyPlugin') { swifty_autoload_lib_helper_main('/php/lib_swifty_plugin.php'); if (is_null(LibSwiftyPlugin::get_instance())) { new LibSwiftyPlugin(); } } if ($class_name === 'LibSwiftyPluginView') { swifty_autoload_lib_helper_main('/php/lib_swifty_plugin_view.php'); if (is_null(LibSwiftyPluginView::get_instance())) { new LibSwiftyPluginView(); } } }
/** * Get a menu_order space to move/insert a page * * @param WP_Post $ref_post * @param string $direction, can be 'before','after' or 'inside' * @return int */ protected function _createSpaceForMove($ref_post, $direction = 'after') { /** @var wpdb $wpdb */ global $wpdb; if ('inside' === $direction) { $query = $wpdb->prepare("SELECT MAX(menu_order) FROM {$wpdb->posts} WHERE post_parent = %d", $ref_post->ID); $result = $wpdb->get_var($query) + 1; } else { // after or before $result = $ref_post->menu_order; if ('after' === $direction) { $result++; } $posts = get_posts(array('post_status' => 'any', 'post_type' => $this->_post_type, 'numberposts' => -1, 'offset' => 0, 'orderby' => 'menu_order title', 'order' => 'asc', 'post_parent' => $ref_post->post_parent, 'suppress_filters' => false)); $has_passed_ref_post = false; foreach ($posts as $one_post) { if ($has_passed_ref_post or 'before' === $direction && $ref_post->ID === $one_post->ID) { $post_update = array('ID' => $one_post->ID, 'menu_order' => $one_post->menu_order + 2); //$return_id = wp_update_post( $post_update, true ); < now keeping autosave $return_id = LibSwiftyPlugin::get_instance()->wp_update_post_keep_autosave($one_post->ID, $post_update, true); if (is_wp_error($return_id)) { die('Error: could not update post with id ' . $post_update['ID'] . '<br>Technical details: ' . print_r($return_id, true)); } } if (!$has_passed_ref_post && $ref_post->ID === $one_post->ID) { $has_passed_ref_post = true; } } } return $result; }