=' ) ) { add_action( 'admin_notices', array( $this, 'requirement_wp_notice' ) ); return false; } return true; } // END check_wp() /** * Show the WordPress requirement notice. * * @access public * @since 1.0.0 */ public function requirement_wp_notice() { include( dirname( __FILE__ ) . '/admin/views/html-notice-requirement-wp.php' ); } // END requirement_wp_notice() /** * Includes the permalink settings. * * @access public */ public function initialize_permalink_settings() { include_once( dirname( __FILE__ ) . '/admin/class-as-permalink-settings.php' ); } // END initialize_permalink_settings() /** * Filters the attachment links * * @access public * @return string $link */ public function attachment_link( $link, $post_id ){ $permalink = get_option( 'attachment_permalink' ); $attachment_slug = $permalink['base']; // Attachment base or custom base. if ( ! empty( $attachment_slug ) ) { $post = get_post( $post_id ); $link = home_url( '/' . $attachment_slug . '/' . $post->post_name . '/' ); } return $link; } // END attachment_link() /** * Add the Attachment Slug rewrite rule * * @access public * @return void */ public function add_rewrite_rule() { $permalink = get_option( 'attachment_permalink' ); $attachment_slug = trim( $permalink['base'], '/' ); // Attachment base or custom base. if ( ! empty( $attachment_slug ) ) { // Add the rewrite rule. add_rewrite_rule('^' . $attachment_slug . '/([^/]*)/?', 'index.php?attachment=$matches[1]', 'top'); } } // END add_rewrite_rule() /** * Make the plugin translation ready. * * Translations should be added in the WordPress language directory: * - WP_LANG_DIR/plugins/attachment-slug-LOCALE.mo * * @access public * @return void */ public function load_plugin_textdomain() { load_plugin_textdomain( 'attachment-slug', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); } // END load_plugin_textdomain() /** * Adds a text field to allow an individual attachment * to have a unique slug. * * @access public * @since 1.0.0 * @global object $post WP_Post * @return void */ public function individual_slug() { global $post; $slug = $post->post_name; echo '

' . __( 'Attachment Slug', 'attachment-slug' ) . '

'; echo '
' . esc_attr__( 'Here you can change the permalink slug for this attachment.', 'attachment-slug' ) . '
'; echo '
'; } // END individual_slug() /** * Saves the individual slug for the attachment * * @access public * @since 1.0.0 * @param int $post_ID Post ID. * @global $wpdb WordPress database abstraction object. */ public function save_individual_slug( $post_ID ) { global $wpdb; $new_slug = isset( $_POST['attachment_slug'] ) ? trim( strip_tags( sanitize_title( $_POST['attachment_slug'] ) ) ) : ''; if ( ! empty( $new_slug ) ) { $wpdb->query( $wpdb->prepare(" UPDATE $wpdb->posts SET post_name = %s WHERE ID = %d ", $new_slug, $post_ID ) ); } } // END save_individual_slug() } // END class } // END if class exists return Attachment_Slug::instance();