plugin_slug; $locale = apply_filters( 'plugin_locale', get_locale(), $domain ); load_textdomain( $domain, WP_LANG_DIR . '/' . $domain . '/' . $domain . '-' . $locale . '.mo' ); load_plugin_textdomain( $domain, FALSE, dirname( plugin_basename( __FILE__ ) ) . '/lang/' ); } /** * NOTE: Actions are points in the execution of a page or process * lifecycle that WordPress fires. * * WordPress Actions: http://codex.wordpress.org/Plugin_API#Actions * Action Reference: http://codex.wordpress.org/Plugin_API/Action_Reference * * @since 1.0.0 */ public function archive_control_custom_admin_style_scripts() { wp_register_style( 'archive_control_admin_css', plugin_dir_url( __FILE__ ) . '/css/admin-style.css', false, '1.0' ); wp_enqueue_style( 'archive_control_admin_css' ); wp_register_script( 'archive_control_admin_js', plugin_dir_url( __FILE__ ) . '/js/admin-scripts.js', 'jquery', '1.0', true ); wp_enqueue_script( 'archive_control_admin_js' ); } public function archive_control_action_link( $links ) { $mylinks = array( '' . __('Settings', 'archive-control') . '', ); return array_merge( $links, $mylinks ); } public function archive_control_menu() { add_options_page( __('Archive Control', 'archive-control'), __('Archive Control', 'archive-control'), 'manage_options', 'archive-control.php', array($this,'archive_control_options') ); $archive_control_options = get_option('archive_control_options'); if ($archive_control_options) { foreach($archive_control_options as $post_type => $options) { if ($options['title'] == 'custom' || $options['before'] == 'textarea' || $options['after'] == 'textarea') { if ($post_type == 'post') { $parent_slug = 'edit.php'; } else { $parent_slug = 'edit.php?post_type=' . $post_type; } add_submenu_page( $parent_slug, __('Edit Archive Page', 'archive-control'), __('Edit Archive Page', 'archive-control'), 'edit_posts', 'edit-archive-' . $post_type, array($this,'archive_control_edit_page_callback') ); } //has before or after value } } } public function archive_control_settings() { register_setting( 'archive-control-options-group', 'archive_control_options' ); $archive_control_options = get_option('archive_control_options'); if ($archive_control_options) { foreach($archive_control_options as $post_type => $options) { register_setting( 'archive-control-' . $post_type . '-group', 'archive_control_' . $post_type . '_title' ); register_setting( 'archive-control-' . $post_type . '-group', 'archive_control_' . $post_type . '_before' ); register_setting( 'archive-control-' . $post_type . '-group', 'archive_control_' . $post_type . '_after' ); } } } public function archive_control_edit_page_callback() { $screen = get_current_screen(); $current_post_type = $screen->post_type; $archive_control_options = get_option('archive_control_options'); $archive_control_cpt_title = get_option('archive_control_' . $current_post_type . '_title'); $archive_control_cpt_before = get_option('archive_control_' . $current_post_type . '_before'); $archive_control_cpt_after = get_option('archive_control_' . $current_post_type . '_after'); if ($screen->post_type == '' && $screen->parent_file == 'edit.php') { $current_post_type = 'post'; } $current_post_type_object = get_post_type_object($current_post_type); $current_post_type_options = $archive_control_options[$current_post_type]; ?>
"; // print_r($query); // print ""; $archive_control_options = get_option('archive_control_options'); foreach($archive_control_options as $post_type => $options) { if (is_post_type_archive($post_type)) { if ($options['order'] !== 'default' && $options['order'] !== null) { $query->set( 'order', $options['order'] ); } //has order value if ($options['orderby'] !== 'default' && $options['orderby'] !== null) { $query->set( 'orderby', $options['orderby'] ); if ($options['orderby'] == 'meta_value' || $options['orderby'] == 'meta_value_num') { if ($options['meta_key'] !== null) { $query->set( 'meta_key', $options['meta_key'] ); } //has meta_key value } //meta_key value is needed } //has orderby value if ($options['pagination'] !== 'default' && $options['pagination'] !== null) { if ($options['pagination'] == 'custom') { if ($options['posts_per_page'] !== null) { $query->set( 'posts_per_page', $options['posts_per_page'] ); } } if ($options['pagination'] == 'none') { $query->set( 'posts_per_page', -1 ); } } //has pagination value } //is_post_type_artchive } //foreach } // is_archive } //is_main_query } //is not admin return; } public static function archive_control_top_content($placement = 'function'){ if (is_archive()) { $archive_control_options = get_option('archive_control_options'); foreach($archive_control_options as $post_type => $options) { if (is_post_type_archive($post_type)) { if ($options['before'] == 'textarea' && $options['before-placement'] == $placement) { $paged = get_query_var( 'paged', 0); if($options['before-pages'] == 'all-pages' || ($options['before-pages'] == 'first' && $paged == 0)) { $archive_control_cpt_before = get_option('archive_control_' . $post_type . '_before'); if ($archive_control_cpt_before) { echo "